Nodemon automatically restarts your application and allows you to try new changes in your ExpressJS application faster.
npm install nodemon --save-dev
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"
},
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
I am using windows os the homebrew only for Apple could you address this
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.
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.
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