Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use nodemon with express js while npm start?

I want to use nodemon to automatically detect changes in my scripts in node.js project and restart when change detected. I have my project setup using express.js. How to use nodemon with express.js, so that when i type npm start, nodemon initiates itself.

like image 824
Abhishek Rathore Avatar asked Aug 07 '17 10:08

Abhishek Rathore


People also ask

How can you start a node JS application from the command line using Nodemon?

Just executing command nodemon index. js will run your project. But if you install Nodemon locally by command npm install nodemon then you have to specify the script. If you name it as start then npm run start or npm start will trigger the server to run.

How do you start Nodemon in VS code?

In order for you to run nodemon with VS Code, you have to set the attribute "restart" to true . This sets the VS Code debugger to re-attach to your node. js application after it is terminated by nodemon. This is useful because nodemon will restart the app on every save made.


1 Answers

Install nodemon as globally first, using these commands

`npm install -g nodemon` or `sudo npm install -g nodemon`

Next, ensure the "scripts" field of package.json file as this type

"scripts": {
    "start":"nodemon index.js",
    "devStart": "nodemon index.js"
}

If not as this type then change it and run npm run devStart

like image 101
Chanuka Avatar answered Sep 20 '22 18:09

Chanuka