Nodemon is not something new to the world of programming as it is one of the tools that are used to develop applications that are based on node.js. When using a nodemon, the node should be replaced with the nodemon in the command at the time of running the script. An error ‘[nodemon] app crashed – waiting for file changes before starting’ pops up when you are working on the nodemon.
This error seems annoying when you get it after executing a long script. Let’s have look at the error that you may get
How ‘[nodemon] app crashed – waiting for file changes before starting’ happens
When you are trying to execute a program using nodemon, you land yourself up in the error. This is how you get the error
Mongoose: users.insert({ firstname: 'firstname', lastname: 'lastname', email:'[email protected]', role: 'admin', password: 'nick', _id: ObjectId("57485c16fc11894b96c28356"), created: new Date("Thu, 13 Oct 2016 15:40:17 GMT"), __v: 0 })
user.save success
node crash
[nodemon] app crashed - waiting for file changes before starting...
You can also get a browser console response like this:
http://localhost:8000/api/users net::ERR_CONNECTION_REFUSED
That’s how you experience the ‘[nodemon] app crashed – waiting for file changes before starting’ error.
Solutions to Fix the “[nodemon] app crashed – waiting for file changes before starting” Error
Check the solutions to get rid of the error
Solution 1 – Kill node process
The error occurs because of the server processes running in the background. To avoid the error, you have to close the terminal. Some programmers use Linux while many use Windows operating system. Let’s discuss see how you can solve the error
For Linux
When working with Linux, every time you get the error, you need to use the below command to close the terminal
pkill -f node
Once done, you just need to restart the nodemon to make it work.
For Windows
If you are a Windows user, then you need to follow the below code
1. Go to the task manager
2. Then look for Node.js: Server-side JavaScript
3. Then right click on it and End task from the processes.
To make it work perfectly, you need to restart the nodemon.
This solution can fix the ‘[nodemon] app crashed – waiting for file changes before starting’ error.
Solution 2 – the Package.json and server.js are not in the same folder
Make sure the Package.json and server.js are not in the same folder as it can cause the error warning. In order to check the file, follow the code
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "nodemon Server.js"
}
Solution 3 – Check for syntax error
The JavaScript syntax error or typing mistake can also be the reason you get an error when compiling. To solve the issue, you need to first check for the syntax by validating, and then to troubleshoot, use the command to debug or run the server manually.
For debugging
$ node --debug server.js
For running the server manually
$ sudo node server.js
or
$ sudo node index.js
Conclusion
And that’s how to tackle the ‘[nodemon] app crashed – waiting for file changes before starting’ error. I hope you find it useful!
I wish you all the best!