NODEMON -- app crashed - waiting for file changes before starting

24,097

Solution 1

That's a typo.

First, what is this (function (exports, require, module, __filename, __dirname) { ... })? It's the module wrapper function. When the exception was thrown, the module already had its wrapper function.

Let's get to the error.

1 > const express = required('express');
                           ^

That's where your typo is.

Now let's get to the [nodemon].

The reason why you got the error message from "[nodemon]" is because you are using a development tool called nodemon for the server.

Solution 2

Simple Answer is:

Go to Mongodb cluster and edit the IPwhitelist and refresh it

then connect it again problem solve.

Happy Coding

Solution 3

This is a very common error, when you start your server with nodemon, you might face this error. So, what this comes? and What is the solution?

ErrorReasons & Solutions:

First: 

Maybe your PC running several processes in the Background. So you need to stop all the node process that are running. 

Quick trick, Kill them all by running this on terminal :

pkill -f node

or to kill a particular port instead of all

sudo lsof -i :8000 //replace 3000 with your port number
sudo kill -9 51009 // replace 31363 with your PID

and then restart nodemon.

Second:

Server.js and package.json are not in the same folder. 

//check package.json
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
     "start": "nodemon Server.js"
 }

Third:

You have written wrong code in your any of the file. So for that make sure you didn't miss any JS syntax. If you did wrong code, here I'm talking about syntax error (not logic), then your nodemon will not start.

Solution 4

You used a word required it is rather require.

The code should be require('express'); on line 1 of the server.js file.

nodemon tries to restart the program for you anytime you encounter an error. Should you effect changes or make the necessary corrections you wouldn't need to run the command node server.js again.

Share:
24,097

Related videos on Youtube

Nick Schmitt
Author by

Nick Schmitt

Updated on February 03, 2022

Comments

  • Nick Schmitt
    Nick Schmitt about 2 years

    I'm following this tutorial.

    When I run npm run server, as at 13:10 in the video, I get the error:

    [nodemon] app crashed - waiting for file changes before starting...

    Why does this happen? Is Port 5000 already in use?


    Here's the terminal:

    #########:MERN_SHOPPING_LIST #######$ npm run server
    
    [email protected] server /Users/MyName/Documents/Web Dev/MERN_SHOPPING_LIST
    nodemon server.js
    [nodemon] 1.18.3
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching: *.*
    [nodemon] starting `node server.js`
    /Users/MyName/Documents/Web Dev/MERN_SHOPPING_LIST/server.js:1
    (function (exports, require, module, __filename, __dirname) { const express = required('express');
                                                                                  ^
    ReferenceError: required is not defined
        at Object.<anonymous> (/Users/MyName/Documents/Web Dev/MERN_SHOPPING_LIST/server.js:1:79)
        at Module._compile (module.js:652:30)
        at Object.Module._extensions..js (module.js:663:10)
        at Module.load (module.js:565:32)
        at tryModuleLoad (module.js:505:12)
        at Function.Module._load (module.js:497:3)
        at Function.Module.runMain (module.js:693:10)
        at startup (bootstrap_node.js:191:16)
        at bootstrap_node.js:612:3
    [nodemon] app crashed - waiting for file changes before starting...
    
    • Eric Silveira
      Eric Silveira over 3 years
      [nodemon] isn't a good tag for this question. The nodemon error was caused by a Node.js error and that error is a typo - the d in required on the first line of your code - and that typo caused a ReferenceError: required is not defined.
    • Eric Silveira
      Eric Silveira over 3 years
      And I also see you're using Mac OS. /Users - that's MacOS stuff. There's a Windows folder with the same name - C:\Users. I know how to distinguish between the two.
  • Nick Schmitt
    Nick Schmitt over 5 years
    When I do that, I get: (node:1731) DeprecationWarning: current URL string parser is deprecated, and willbe removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. BUT I also get Server started on port 5000 MongoDB Connected... So I guess it's a success?
  • Cin88
    Cin88 over 3 years
    That actually worked for me last night, but this morning my app did the same thing. I have to keep refreshing that? :/