
Last updated: Apr 5, 2024
Reading timeยท5 min

The error "[nodemon] app crashed - waiting for file changes before starting..." occurs for multiple reasons:
nodemon to crash.nodemon command.nodemon to crash.
The first thing you should do is try to restart your nodemon server.
Focus your terminal and press Ctrl + C (or Cmd + C on macOS) to stop
your development server.
Then start your nodemon server by issuing the following command.
npx nodemon index.js

Make sure to replace index.js with the name of your specific file.
You might have multiple Node.js processes running in the background that clash and cause the error.
Try to stop all Node.js processes and restart Nodemon.
On macOS and Linux, open bash and issue the following command.
# for macOS and Linux pkill -f node

If you get a permissions error, try to rerun the command prefixed with sudo.
# for macOS and Linux sudo pkill -f node
An alternative approach to stop all Node.js processes is to issue the following command.
# for macOS and Linux killall -9 node # ๐๏ธ or sudo killall -9 node

Restart your nodemon development server after stopping all Node.js processes.
npx nodemon index.js
If you have nodemon installed globally, you can also use it directly, without
the npx prefix.
nodemon index.js
To stop the Node.js processes on Windows:


Alternatively, you can issue a command from your terminal (CMD) to stop the running Node.js processes.
taskkill /F /IM node.exe

Restart your nodemon development server after stopping all Node.js processes.
npx nodemon index.js
If you have nodemon installed globally, you can also use it directly, without
the npx prefix.
nodemon index.js
nodemon to crashThe error is also caused if you have an error in your code (unrelated to
nodemon).
Here is an example.
const site = 'bobbyhadz.com'; // โ๏ธ Example variable is not defined console.log(example);
The example variable is not defined, so trying to access it causes an error.
Now, I'll start my nodemon server by issuing the following command.
npx nodemon index.js
Here is the output in my terminal.

Notice that there is another error above the nodemon error.
nodemon crash error.The error with the undefined variable has caused my nodemon server to crash.
If you have an error in your code, nodemon crashes instantly and is not able
to respond to requests.
The only way to resolve the issue is to solve the error and restart nodemon.
In many cases, even after resolving the error in your code, nodemon isn't
going to restart itself.
You can press Ctrl + C (or Cmd + C on macOS) to manually stop the
server.
After the error is resolved, start nodemon by issuing the following command.
npx nodemon index.js
A common source of errors is when you forget to initialize environment variables in your code but try to access them.
If you try to access environment variables (process.env.X) that you haven't
initialized:
nodemon will crashOther common sources of errors are incorrect import statements.
// โ๏ธ Error module is NOT called azios const axios = require('azios');
The example above causes the error because we have misspelled the name of the module.
// โ correct import statement const axios = require('axios');
The error is also caused if you specify an incorrect path to the file you're trying to run.
For example, here is the scripts section of my package.json file.
"scripts": { "dev": "nodemon index.js", }
The dev script points nodemon to a file called index.js that is located in
the same directory as the package.json file.
my-project โโโ index.js โโโ package.json
However, my index.js file is located in an app directory.
my-project โโโ app โโโ index.js โโโ package.json

If I try to issue the npm run dev command, the "[nodemon] app crashed" error
occurs.

Notice that there is another error above the nodemon error.
Nodemon cannot find the index.js file at the specified location.
One way to solve the error is to update the dev command in my package.json
file.
"scripts": { "dev": "nodemon app/index.js" },
Now the command points to an index.js file located in the app directory.
You can also use the ./ prefix when specifying the path.
"scripts": { "dev": "nodemon ./app/index.js" },
The command assumes the following folder structure.
my-project โโโ app โโโ index.js โโโ package.json
Alternatively, you can move your index.js file to the root directory of your
project, right next to your package.json file.
Assuming you have the following folder structure.
my-project โโโ index.js โโโ package.json
Then your dev command would look as follows.
"dev": "nodemon index.js",

Another common cause of the error is trying to connect to a database (e.g. MongoDB or MySQL) that is offline.
Make sure that your database is up and running before you start your nodemon
server, otherwise an error is raised and nodemon crashes.
To solve the error "[nodemon] app crashed - waiting for file changes before starting...", make sure:
nodemon command.Finally, try to restart your nodemon server.
Focus your terminal and press Ctrl + C (or Cmd + C on macOS) to stop
your development server.
Then start your nodemon server by issuing the following command.
npx nodemon index.js
Make sure to replace index.js with the name of your specific file.
You can learn more about the related topics by checking out the following tutorials: