Nodemon kept looking for index.js
Asked Answered
A

4

6

My Nodemon kept start and looking for index.js, but I want to use app.js as most people now use app.js.

enter image description here

How do I update my nodemon to look for app.js instead ?

I tried to uninstall, reinstall is not help.


⚡️  vidjot  nodemon
[nodemon] 1.17.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
module.js:540
    throw err;
    ^

Error: Cannot find module '/Users/bheng/Sites/vidjot/index.js'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
[nodemon] app crashed - waiting for file changes before starting...

package.json

{
  "name": "vidjot",
  "version": "1.0.0",
  "description": "app to create video idea",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3"
  }
}
Angelitaangell answered 13/4, 2018 at 15:20 Comment(10)
13.5k rep and you posted an image of code?Bolivar
I was thinking to share the error and that's it, trying to keep it simple. This error has nothing to do with code. It should be the configuration of nodemon. I think.Angelitaangell
are you running npm run nodemon?Cavern
no, I just run nodemon, should I ?Angelitaangell
also would be good if you can share scripts in package.json?Cavern
@ihue try npm run nodemonCavern
All you run is nodemon? It's probably defaulting to index.js. Run nodemon app.jsGentle
change main: app.jsCavern
I got it. I found the answer I was looking for. I think I just need to update this line from "main": "index.js", --> "main": "app.js",Angelitaangell
@AnshumanJaiswal : yep ! you're right ! YOu gave me the hint of package.jsonAngelitaangell
O
11

Nodemon command search for the main property at you package.json file and tries to execute it's file. Example:

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "henriquelborges",
  "license": "ISC"
}

You can change "main": index.js" to "main": "app.js". Or you can run "nodemon filename" to specify the entry file. What I usually do is add scripts to my package.json. Example:

"scripts": {
    "start": "node app.js",
    "test": "nodemon app.js"
},

After this I just use commands like "npm start" or "npm test" at my project root folder. Cloud application platforms like Heroku needs "npm start" at your package.json in order to execute your app. Adding npm commands to your projects is also useful in case you need to load other npm modules from command line.

Example - you can load your environment variables to test your app at localhost with:

"test": "nodemon -r dotenv/config app.js dotenv_config_path=./config.env"

Oocyte answered 13/4, 2018 at 15:26 Comment(0)
R
2

As stated in nodemon documentation, you just have to specify the entrypoint of your application in argument:

nodemon ./app.js

Or you can specify it in your package.json file:

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "henriquelborges",
  "license": "ISC"
}
Ribeiro answered 13/4, 2018 at 15:29 Comment(0)
C
1

it should be app.js instead index.js as:

...
"main": "app.js",
...
Cavern answered 13/4, 2018 at 15:27 Comment(0)
S
0

you should edit main value in the package.json :

change:

{
...
"main":"index.js"
...
}

to:

{
...
 "main":"app.js"
...
}
Shayn answered 7/7, 2021 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.