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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With