Using nodemon without a global installation
Problem:
You want to use nodemon in order to automatically reload your NodeJS server, however you don’t want to require a global installation (npm install -g nodemon
) but instead install it locally into the node_modules
directory:
Solution:
First, install nodemon as dependency (
npm install --save-dev nodemon
We installed it as development dependency for this example, but it will work just as well if you install it as a normal dependency using --save
instead of --save-dev
.
After that, add a script entry in package.json
:
"scripts": {
"devserver": "./node_modules/nodemon/bin/nodemon.js index.js"
}, /* rest of package.json */
Replace index.js
with the name of the file you want to run using nodemon
.
Now you can start the development server using
npm run devserver