Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
Argumentless nodemon command in npm project does not run value of "main" from package.json

I have an npm project with the following folder structure:

project
├── node_modules
│   └── (node_modles folders)
├── server.js
├── index.js
├── index.html
├── package.json
└── package-lock.json

My index.js is my front end JavaScript code of this little Web app. And my server.js is the back end. I'm using nodemon (version 2.0.16) to run my server.js file, which is a simple Express app:

const express = require('express');
const app = express();
app.listen(4000, () => {console.log('Listening on port 4000')})

To run my server, I run nodemon server.js in my terminal, and my Express app runs correctly. However, the Nodemon docs say:

If you have a package.json file for your app, you can omit the main script entirely and nodemon will read the package.json for the main property and use that value as the app (ref).

So, I figure that if my package.json file looks like this

{
  "main": "server.js",
  "dependencies": {
    "express": "^4.18.1"
  }
}

then I should be able to just run nodemon instead of nodemon server.js, and everything should work the same. However, this is not the case. When I simply run nodemon with this setup, it's apparently trying to run my index.js file regardless of what I have for "main" in my package.json file. Can anyone explain why I can't just run nodemon without arguments in this case?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It appears that if I delete index.js, running the no-argument nodemon command works as expected. However, if there is a file named index.js at the root of the project, then that file will get run no matter what I put for "main" in package.json.

I'm not sure if this is working-as-designed or if it was intended to have the "main" value ignored like this. I couldn't find a mention of the precedence in the docs.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda