Nodemon with Express Generator?

Express generator requires using a complex command to start the server

DEBUG=url-shortener:* npm start

Nodemon usually uses nodemon <entry_file_name> Is that safe to use or should another library be used to auto-restart an Express Generator server?

You need to modify the package.json script command that starts the server.

The important bit there is npm start. That’s all that’s being run, the bit before is setting an environment variable. So you need to check what is being executed - it is likely something like node app.js so you would add nodemon as a dependency then change node app.js to nodemon app.js

2 Likes

For anyone else who had this problem. @DanCouper is def correct. in the package.json file you can actually use a a little shortcut, but just installing nodemon(npm install nodemon --save) to the dependencies then in the package.json under “scripts” there’s a “start” command that appears as so:
“start”: “node ./bin/www” you just change that to “start”: “nodemon ./bin/www” and now you can run “nodemon start” from the CLI and you’ve got hot reload.

1 Like