Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda