Installing Nodemon

    Learn how to install nodemon for your ExpressJS application. 

    Bahadir Balban

    Started Tech Buzz

    @learningexpressjs

    Nodemon automatically restarts your application and allows you to try new changes in your ExpressJS application faster.

    Installing Nodemon

    npm install nodemon --save-dev

    Invoking nodemon in your startup script

    Replace the script section as below in your package.json:

    "scripts": {
        "start": "if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi"
      },


    Did you like this episode?

    Buzz it and share it with your friends

    Buzz1

    You Might Also Like...


    Join The Discussion

    sdot

    @sfamilia

    Jun 30

    so i installed nodemon but then when i DEBUG=myapp:* npm start, i keep getting the same error of "SyntaError: Unexpected Identifier" and [nodemon] app crashed - waiting for file changes before starting... what should i do? nothing is working after this point

    Gabriel Afolabi

    @gabriel

    Sep 1

    I am using windows os the homebrew only for Apple could you address this

    Bahadir Balban

    @b

    May 2

    Sorry, I realized that this was an OS specific shell script, in this case, Linux/Bash. Solution: Use a different command for production and developer, also use the right command for your operating system. For example: "start": "node ./bin/www", "dev:start":"nodemon ./bin/www" Then use npm run dev:start for starting the server in developer environment, and use npm run start for starting it in production. This essentially removes the OS specific if / else shell script statements, and it should now work on windows. I hope this helps.

    Mar 22

    I try to run it in Windows PowerShell, but getting the error: PS D:\work\NodeJS\test\myapp> npm start > myapp@0.0.0 start D:\work\NodeJS\test\myapp > if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi $NODE_ENV was unexpected at this time. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! myapp@0.0.0 start: `if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the myapp@0.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    Aashish Chhabbi

    @aashish

    Feb 17

    I am getting this error when I run the program after making changes to the script myapp@0.0.0 start C:\Windows\System32\myapp > if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi $NODE_ENV was unexpected at this time. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! myapp@0.0.0 start: `if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the myapp@0.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\ashis\AppData\Roaming\npm-cache\_logs\2019-02-17T21_23_56_139Z-debug.log