Nodemon app crashed waiting for file changes before starting как исправить

In this post, I will give you 5 solutions, If you are getting a "nodemon app crashed - waiting for file changes before starting" error while trying to start

In this post, I will give you 5 solutions, If you are getting a «nodemon app crashed — waiting for file changes before starting» error while trying to start your server with nodemon. This error generally occurs due to multiple node processes are running in the background or some syntax error in your code.

Below mentioned are the errors, you may encounter during the nodemon server start process —

  • Nodemon app crashed
  • Nodemon app crashed — Waiting for file changes before starting
  • App crashed waiting for file changes
  • App crashed nodemon
  • Nodemon app crashed waiting for file changes

Following are the reasons for the above-mentioned errors:-

  1. Lot of node processess are running in background
  2. Package.json and server.js are not in the same folder
  3. Forgot to source your .env files
  4. Changed the file at the same time you save nodemon debugger working
  5. In case of MongoDB, issue with cluster

Let’s deep dive and see the solutions to fix the nodemon app crash issue.

Table of Contents

  • 1 How to fix «Nodemon app crashed — Waiting for file changes before starting» error
  • 2 Solution2 — Check for any JS syntax error in your code and run your server manually to debug error
  • 3 Solution3 — Validate Package.json and server.js are not in the same folder
  • 4 Solution4 — Source your environment (.env) file
  • 5 Solution5 — Validate MongoDB cluster is working fine
  • 6 Summary

I have jotted down 5 possible solutions for the nodemon app crashed issue for you. Try to follow all these solutions one by one, I am sure you will get your issue fixed.

Nodemon app crashed - Waiting for file changes before starting

Solution1 — Check and kill node processes to fix Nodemon app crashed issue

I am sharing options for Windows and Linux both. So based on your operating system, you can choose your steps.

For Linux —

  • Look for process id of node and make a note. This pid will be used as input in second command.
$ ps aux | grep -i node
  • Kill the process
$ sudo kill -9 [Process-ID]

or

$ sudo killall -9 node

Or you can also kill a specific port instead of killing all node processes

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

For Windows

  • <Right click> on «Taskbar» and open Task manager
  • Check for the process Node.js: Server-side JavaScript in list
  • Select process and Click «End task» to kill node processes

It will fix the «Nodemon app crashed — Waiting for file changes before starting» error issue for sure.

Solution2 — Check for any JS syntax error in your code and run your server manually to debug error

Typing mistakes and JS syntax errors are the most common issues, which will stop your nodemon to start and will result in a nodemon app crashed error.

Once you validated that syntax is correct and there are no typing mistakes. Try running your server manually or use debug command to troubleshoot further.

  • Try Starting server manually
$ sudo node server.js

or

$ sudo node index.js

Run Nodemon server manually

  • Use debug option while running server
$ node --debug server.js

Solution3 — Validate Package.json and server.js are not in the same folder

To validate Package.json and server.js are not in the same folder. Open your Package.json file and check —

"scripts": {
    "test": "echo "Error: no test specified" && exit 1",
     "start": "nodemon Server.js"
 }

The below-mentioned image reflects the default entries in the package.json file after nodemon installation.

Package.json file default entries

Solution4 — Source your environment (.env) file

Don’t forget to source your environment variable file. Sometimes, if you forgot to source your «.env» file, that also results in the Nodemon app crashed — Waiting for file changes before starting» error. Check out this article for more information.

Solution5 — Validate MongoDB cluster is working fine

In the case of Mongo DB, make sure your cluster is working fine and restart your application. In addition, re-check for the mongo connection URL which was saved in default.json.

Summary

Above mentioned solutions fix approximately all nodemon crashed issues. If you follow all instructions carefully, I am confident, one of these solutions will fix your «Nodemon app crashed — Waiting for file changes before starting» error.

If you still get any issues, you can reply via comments and I will try to help you in the best possible way.

Happy Learning.

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Comments

@BramDecuypere

I have this situation where I had a perfectly working app and all the request were not a problem at all. But after changing this piece of code:

exports.read = function (req, res) {
  res.json(req.external);
};

into:

exports.read = function (req, res) {
  //res.json(req.external);
  console.log(req.external);
  console.log('start----------');
  External.findById(req.external._id)
    .populate('user', 'displayName')
    .populate('articles')
    .exec(function (err, external) {
      console.log('in execution mode');
      if (err) {
        console.log('ERROR ERROR ERROR');
        return res.status(400).send({
          message: errorHandler.getErrorMessage(err)
        });
      } else {
        console.log('There is no error generated!');
        res.json(external);
      }
    });
};

After a few seconds my app crashes, although it sends the correct information to the
front-end? Anyone a solution? Because I have no clue how to fix this and at the moment I’m stuck.
The code doesn’t get into the console.log(‘ERROR ERROR ERROR’); part.

@remy

Does this crash if you use node and not nodemon? (i.e. just running the 2nd code block).

@allthetime

@remy Hey, I have the same problem. Code that works with node, will crash nodemon, and it is ALWAYS because of console.log statements contained in callbacks that print referenced data.

So console.log('test') will not crash nodemon, but console.log(db_results) or console.log(error) where db_results is an array of objects and error is a multi-line string will reliably crash nodemon.

My coworker doesn’t seem to have this issue, but I certainly do.

Removing console logs fixes the issue, but this isn’t exactly acceptable for obvious reasons.

I’m running the newest version of node (5+) on OSX

@leslyarun

@remy Hi, even I have the issue. If I run from node, it runs perfectly allright. But if i run from nodemon, its crashing :

$ nodemon
[nodemon] 1.8.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `./node_modules/.bin/babel-node --presets react,es2015 server.js`
'.' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
CavalcanteLeo, davidvuong, praneshkmr, EvgenijMerchansky, Hevanafa, Magamex, SMAsad, HebutJipeng, yanhong343333416, JoseAlbb, and 10 more reacted with confused emoji

@allthetime

I think the biggest issue is nodemon hiding error messages, or crashing just before displaying them. I have recently come up against a few cases where when running nodemon all I get is [nodemon] app crashed - waiting for file changes before starting... but if I run the server by itself with node, I get a full explanation/stack trace as to why the app crashed.

Otherwise, it seems nodemon is watching too many files for my system to handle, I believe this is an issue with my own setup as much as it is with nodemon. When using a lot of node_modules (and some python libraries) there are A LOT of files to watch, most of which I don’t need to watch. I have attempted to use nodemon.json to exclude certain patterns… "node_modules/**" for instance, but it doesn’t seem to have any effect.

seanfuture, adamhrosenberg, gnobre, nadeemramsing, shashankmb94, singular1ty94, MaxHoefl, imVinayPandya, Nikkov17, KianaMsqt, and 4 more reacted with thumbs up emoji
adamhrosenberg and pranjalia reacted with laugh emoji
adamhrosenberg, ragupathis, and midas0925 reacted with hooray emoji
adamhrosenberg, Slashere, and duc110789 reacted with heart emoji

@pursual

Had this issue with node ver 4.2.6, but not when downgrading back to 4.2.2.

@michaelBenin

Also having this issue with 4.2.6

  • Working fine in 5.6.0

@remy

Has anyone attempted to debug this yet?

@Neta-Alon

Hey guys,
I had it happen to me, don’t know if for the same reason.
My problem was I forgot to close pm2 running my production version before attempting to start nodemon.
Only after a while did nodemon give me an error saying it can’t listen on the already bound port.

@xiaofan2406

It happened to me as well. It crashes without giving any other error message.
I closed all the terminal window, and restarted it. Then it works again.

@seanfuture

@remy also experiencing this issue regularly on OS X only when running nodemon. Haven’t had time to debug but I can say that app in question that’s wrapped with nodemon routinely outputs console messages ( have no idea if that’s related or not however ) .. no error message reported other than what’s been listed by previous commenters. Was not using pm2, instead was simply running gulp which executed nodemon.

@kingram6865

Does someone have a solution as opposed to confirming that this is a problem?

@samiraguiar

@remy This is happening to me on Windows 10 with node v6.9.4 and nodemon 1.11.0, but only when I pass the --debug flag. For some reason, the signal received by nodemon is null and it’s expecting SIGUSR2. Maybe this is related to #335?

@praWINK

I am also having this same issue anyone could solved that…

@Massimoivaldi

Don’t ask me why but if i change the port (it was 300 i put 3000) nodemon doesn’t crash anymore.

@shubhamduttasd

mine is 3001 so what should i put?

@am-firnas

worked for node 5.6.0 version.

am-firnas

added a commit
to am-firnas/StudentBlogging
that referenced
this issue

Jul 2, 2017

@am-firnas

@shikya

"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"cors": "^2.8.4",
"express": "^4.15.3",
"jsonwebtoken": "^7.4.1",
"mongoose": "^4.11.3",
"passport": "^0.3.2",
"passport-jwt": "^2.2.1"

node => v6.10.0
npm => 5.3.0
nodemon => 1.11.0

npm install => done.

screen shot 2017-07-22 at 4 53 25 pm

@MrBeboApp

probblem
[nodemon] app crashed — waiting for file changes before starting…

@avinashpj

Temp solution: I have changing port when this error msg come, its working.

@remy

Sorry folks, but this thread has become awfully confused. I’m going to close it and if anyone still has a specific issue (and can create a replicable example with a gist containing files required), then please go ahead and open a new issue and I can (or you — please do contribute) attempt a PR.

lasergoat, camdagr8, emily-le, 0xKayvan, brijendra98, IvanSakhman, iantheninja, saadqc, nadeemramsing, MajorKuprich, and 30 more reacted with thumbs down emoji

@tech2crave

I have the same problem as many here.. I am new to node.js.. and while I have been reading your comments.. there is a possibility that the issue is nodejs version running with certain version of nodemon.. i am wondering what versions are you guys using..

I am running
«nodemon»: «^1.17.3» and node.js 8.11.1 .. would you guys recommend that I downgrade to an earlier version of node.js or nodemon? if so, what is would be the best version pairing that you guys are running?

@remy

@tech2crave I’d suggest opening a new issue with details of what you’re seeing. The original issue was opened 2 years ago when node support was very different. Node 8 should be very well supported, so if you file the new issue with full information on how to replicate, that would be perfect

@kumaresan-in

DavidMorton, bcongdon, ZHamburglar, yusuf-khamis, DestructChen, gregtyler, NikitaChernykh, gowda, michaeljohansen, MartinBucko, and 31 more reacted with thumbs down emoji

@TaoWang317

Try this probably.
Run ‘npm install monk —save’ under your node project folder.
Then run ‘nodemon’ again.
This should fix the problem.

eclectic-coding reacted with thumbs up emoji
backslash112, michaeljohansen, GCesnik, leandrobeandrade, kalpeshsatasiya, G-Chilie, pshobha97, KohliSuraj, calumgunn, tandat2209, and 8 more reacted with thumbs down emoji

@mukuljainx

Hey everyone, updating nodemon from version 1.18.6 to 1.18.9 fixed the issue for me.

@corysimmons

@mukuljainx 1.18.9 doesn’t help.

Might be easier to debug if errors were surfaced instead of just [nodemon] app crashed - waiting for file changes before starting... ?

After some digging (removing code) I figured out it was buggy middleware. I suggest if anyone else is running into this while using Express, to do the same.

@thisilvafarias

@corysimmons you are right, that error can be something wrong in the code. I am using express and mqtt, when I type some variable that wasn’t declared I get that error. [nodemon] app crashed — waiting for file changes before starting…

@erics2783

For me, error messages were getting hidden by winston. My winston transport had handleExceptions: true. In my particular case, the port was already in use but that error only showed up on my logging server. When i set handleExeptions: false, I started to get the error message in my console.

aaronhayes, FunctorDev, dantaeusb, ssss1029, RoyalRajdeep, raeun-edu, mosrahmani, Amesys, and devguy221 reacted with thumbs up emoji
Amesys and devguy221 reacted with laugh emoji
Amesys and devguy221 reacted with hooray emoji
FunctorDev, ssss1029, raeun-edu, mosrahmani, Amesys, and devguy221 reacted with heart emoji
FunctorDev, raeun-edu, mosrahmani, Amesys, and devguy221 reacted with rocket emoji

@MiguellAngelhs

Many times we closed the PC and left the project running, when we used it again and ran the project again, that error appeared. I always solved it, restarting the pc. Everything worked perfectly.

@kphareesh1994

root@DC-Development:~# docker logs 511b1f3b6821
[nodemon] 1.19.1
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node ./bin/www
module.js:550
throw err;
^

Error: Cannot find module ‘http-errors’
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (/tvstyres/app.js:1:83)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
[nodemon] app crashed — waiting for file changes before starting…
Facing same Nodemon app crashed issue can any one help me in fixing the issue

@aricjean

I had it happen to me, but I just figured it out.

change
"dev:watch": "nodemon --watch './src/**/*' -e ts,tsx --exec 'ts-node' ./src/index.ts",
to
"dev:watch": "nodemon --watch ./src/**/* -e ts,tsx --exec ts-node ./src/index.ts",
just remove those single quotes.

@sakshiseth

I got the same error, the possible solution is to free up the port.
Use the following commands:
sudo pkill node
or
kill $(lsof -t -i:5000)
Instead of 5000, use your port number.

@memeteli

It happened to me also when I tried to run nodemon from CLI, but after I added it into my package.json script and run with npm it works, I don’t know why, but hope this helps.

@ionicstuff

@CinatitBR

Try to open the task manager and kill the node.js processes.

It worked for me.

image

@analopesdev

It worked for me !!!
see if your task manager or node.js is running, finish the task, close your project and open again by running on port 5000.

@vikramvi

Issue still exists with below setup, tried all the steps mentioned above but none of them worked.
I’m working on MERN stack project

"devDependencies": {
    "nodemon": "^2.0.4"
  }

"engine": {
    "node": "14.8.0",
    "npm": "6.14.7"
  }

@Hasankc

Same here i face the same problem nay Help?
at node:internal/main/run_main_module:17:47
[nodemon] app crashed — waiting for file changes before starting…

@ManalLiaquat

Updating node.js to v14 solves this issue on my PC

@shayneoneill

Same problem w/ v 2.0.16. Gives me the app-crash -waiting for files, but doesnt actually tell me where in this giant codebase I’ve inhereted the actual error is :(

@HampusHauffman

For me it was also an issue with winston. I had to use the following logger:

 winston.createLogger({
    level: 'debug',
    format: winston.format.combine(
      winston.format.errors({ stack: true }),
      winston.format.metadata(),
    ),
    transports: new winston.transports.Console(),
  }),

Then you can add the following to make it look better:

      winston.format.timestamp(),
      winston.format.prettyPrint(),

EDIT
After further testing, I have found that this is happening with both gulp and grunt on this app and on the default install of mean.js. I’m running this locally on a Mac. When I running either app using «node server.js» they don’t crash.

I’m using a MEAN stack with grunt-nodemon and node is crashing when an express URL is accessed. It isn’t always consistent though. Sometimes it works, sometimes node crashes right when the URL is hit retiring no data, and other times I get a response and node crashed immediately after.

Browser console response:

http://localhost:8000/api/users net::ERR_CONNECTION_REFUSED

Terminal output:

Mongoose: users.insert({ firstname: 'mike', lastname: 'jones', email:'[email protected]', role: 'admin', password: 'mike', _id: ObjectId("57485c16fc11894b96c28057"), created: new Date("Fri, 27 May 2016 14:39:18 GMT"), __v: 0 })   
user.save success
node crash
[nodemon] app crashed - waiting for file changes before starting...

In this case, the POST request went through, the user was added, then node crashed, but sometimes it crashes before a successful POST. Node also occasionally crashes on the GET request.

gruntfile.js:

module.exports = function(grunt) {
    // Load grunt tasks automatically
    require('load-grunt-tasks')(grunt);

    var pkg = grunt.file.readJSON('package.json');

    var options = {
        paths: {
            app: 'app',
            assets: 'app/assets',
            dist: 'app/dist',
            distAssets: 'app/dist/assets',
            html: 'app/html',
            htmlTmp: '.tmp/htmlsnapshot',
            htmlAssets: 'app/html/assets',
            index: 'app/dist/index.html',
            indexDev: 'app/index.html',
            indexTmp: '.tmp/html/index.html'
        },
        pkg: pkg,
        env: {
            test: {
                NODE_ENV: 'test'
            },
            dev: {
                NODE_ENV: 'development'
            },
            prod: {
                NODE_ENV: 'production'
            }
        }
    };

    // Load grunt configurations automatically
    var configs = require('load-grunt-configs')(grunt, options);

    // Define the configuration for all the tasks
    grunt.initConfig(configs);

    // Connect to the MongoDB instance and load the models
    grunt.task.registerTask('mongoose', 'Task that connects to the MongoDB instance and loads the application models.', function () {
        // Get the callback
        var done = this.async();

        // Use mongoose configuration
        var mongoose = require('./config/lib/mongoose.js');

        // Connect to database
        mongoose.connect(function (db) {
            done();
        });
    });

    grunt.registerTask('bumper', ['bump-only']);
    grunt.registerTask('css', ['sass']);
    grunt.registerTask('default', [
        'sass',
        'copy:dev',
        'nodemon',
        'concurrent:dev',
        'watch',
        'mongoose'
    ]);

    grunt.registerTask('shared', [
        'clean:demo',
        'copy:demo',
        'sass',
        'ngconstant',
        'useminPrepare',
        'concat:generated',
        'cssmin:generated',
        'uglify:generated',
        'filerev',
        'usemin',
        'imagemin',
        'usebanner'
    ]);

    grunt.registerTask('demo', [
        'shared',
        'copy:postusemin',
        'grep:demo'
    ]);

    grunt.registerTask('dist', [
        'shared',
        'copy:postusemin',
        'copy:dist',
        'grep:dist',
        'compress',
        'copy:postusemin',
        'grep:demo',
    ]);

    grunt.loadNpmTasks('grunt-forever');

};

default.js

module.exports.tasks = {
    // version update
    bump: {
        options: {
            files: ['package.json', 'bower.json'],
            pushTo: 'origin'
        }
    },

    // application constants
    ngconstant: {
        options: {
            dest: '<%= paths.assets %>/js/app.constants.js',
            name: 'app.constants',
        }
    },

    // remove all bs from css
    cssmin: {
        options: {
            keepSpecialComments: 0
        }
    },
    markdown: {
        all: {
            files: [
                {
                    src: 'README.md',
                    dest: '<%= paths.assets %>/tpl/documentation.html'
                }
            ],
            options: {
                template: '<%= paths.assets %>/tpl/_documentation_template.html',
            }
        }
    }
};

dev.js:

var _ = require('lodash'),
defaultAssets = require('./assets/default'),
testAssets = require('./assets/test'),
testConfig = require('./env/test'),
fs = require('fs'),
path = require('path');

module.exports.tasks = {
    // copy files to correct folders
    copy: {
        dev: {
            files: [
                { expand: true, src: '**', cwd: '<%= paths.app %>/bower_components/font-awesome/fonts',                    dest: '<%= paths.assets %>/fonts' },
                { expand: true, src: '**', cwd: '<%= paths.app %>/bower_components/material-design-iconic-font/fonts',     dest: '<%= paths.assets %>/fonts' },
                { expand: true, src: '**', cwd: '<%= paths.app %>/bower_components/roboto-fontface/fonts',                 dest: '<%= paths.assets %>/fonts' },
                { expand: true, src: '**', cwd: '<%= paths.app %>/bower_components/weather-icons/font',                    dest: '<%= paths.assets %>/fonts' },
                { expand: true, src: '**', cwd: '<%= paths.app %>/bower_components/bootstrap-sass/assets/fonts/bootstrap', dest: '<%= paths.assets %>/fonts' }
            ]
        }
    },

    // watch for changes during development
    watch: {
        js: {
            files: ['Gruntfile.js', '<%= paths.assets %>/js/**/*.js'],
            tasks: ['jshint'],
            options: {
                livereload: true
            }
        },
        css: {
            files: [
                '<%= paths.assets %>/css/**/*.scss'
            ],
            tasks: ['sass'],
            options: {
                livereload: true
            }
        },
        markdown: {
            files: [
                'README.md'
            ],
            tasks: ['markdown']
        },
        tasks:  [ 'express:dev' ],
    },

    // debug while developing
    jshint: {
        all: ['Gruntfile.js', '<%= paths.assets %>/js/**/*.js']
    },
    concurrent: {
        dev: {
            tasks: ['nodemon', 'node-inspector', 'watch'],
            options: {
                logConcurrentOutput: true
            }
        }
    },
    nodemon: {
        dev: {
            script: 'server.js',
            options: {
                nodeArgs: ['--debug'],
                ext: 'js,html',
                callback: function (nodemon) {

                    nodemon.on('crash', function (event) {
                        console.log(event);
                    });


                },
                watch: _.union(defaultAssets.server.gruntConfig, defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
            }
        }
    },
    forever: {
        server1: {
            options: {
                index: 'server.js',
                //logDir: 'logs'
            }
        }
    }
};

Angular controller function:

  $scope.addUser = function(){

      var user = {
          firstname: $scope.firstname,
          lastname: $scope.lastname,
          email: $scope.email,
          role: $scope.role.selected,
          password: $scope.password
      };

      $http.post('/api/userAdd', user ).then(function successCallback(response) {
          $location.path('/users');
      }, function errorCallback(response) {
          console.log('error addding user');
          console.log(response);
      });
  };

Express route:

User = require('../models/user.js');

module.exports = function (app) {

    app.get('/api/users', function (req, res) {

        User.find({}, function (err, users) {
            if ( err ) {
                res.send({
                    message : 'error finding users',
                    success: false
                });
            } else {
                res.json(users);
            }
        });

    });

    app.get('/api/users', function (req, res) {
        User.find({fields: {}}, function (err, docs) {
            res.json(docs);
        });
    });

    app.post('/api/userAdd', function (req, res) {

        var user = new User(req.body);

        user.save( function( err, user ){

            if (err){
                console.log('user.save error');
                console.log(err);
                res.send({
                    success: false
                });
            } else {
                console.log('user.save success');
                res.send({
                    success: true
                });
            }
        });

    });

};

I’m also testing with Chromes Advanced REST extension and with any request using this tool node crashes immediately.

I’m new to MEAN so am I missing something here that is causing the crash? Any ideas?

Like this post? Please share to your friends:
  • Node js setup wizard ended prematurely because of an error
  • Node js cannot get ошибка
  • No world with name deerisle ошибка
  • No wgl extensions как исправить на эмуляторе
  • No valid sound devices connected attack on titan как исправить