'Nodemon - "clean exit - waiting for changes before restart" during setup

I am trying to set up a RESTful API with Node and Postgres. I have run into a problem where whenever I attempt to run the server (using npm start) to test it locally, I get the following output:

[nodemon] 1.14.10 [nodemon] to restart at any time, enter rs [nodemon] watching: . [nodemon] starting node index.js server.js [nodemon] clean exit - waiting for changes before restart

After searching online for quite some time, I cannot find too many resources on what exactly "clean exit - waiting for changes before restart" exactly means, especially in this case.

This is my queries.js file:

  1 var promise = require('bluebird');
  2 
  3 var options = {
  4   // Initialization Options
  5   promiseLib: promise
  6 };
  7 
  8 // created an instance of pg-promise, override default pgp lib w bluebird
  9 var pgp = require('pg-promise')(options);
 10 var connectionString = 'postgres://localhost:3000/actions';
 11 var db = pgp(connectionString);
 12 
 13 // add query functions
 14 
 15 module.exports = {
 16   getAllActions: getAllActions,
 17 //  getSingleAction: getSingleAction,
 18 //  createAction: createAction,
 19 //  updateAction: updateAction,
 20 //  removeAction: removeAction
 21 };
 22 
 23 function getAllActions(req, res, next) {
 24   db.any('select * from acts')
 25     .then(function (data) {
 26       res.status(200)
 27         .json({
 28           status: 'success',
 29           data: data,
 30           message: 'Retrieved ALL actions'
 31         });
 32     })
 33     .catch(function (err) {
 34       return next(err);
 35     });
 36 }

Here is my index.js file:

  3 var express = require('express');
  4 var app = express();
  5 var router = express.Router();
  6 var db = require('./queries');
  7 
  8 // structure: expressInstance.httpRequestMethod(PATH, HANDLER)
  9 app.get('/api/actions', db.getAllActions);
 10 //app.get('/api/actions/:id', db.getSingleAction);
 11 //app.post('/api/actions', db.createAction);
 12 //app.put('/api/actions/:id', db.updateAction);
 13 //app.delete('/api/actions/:id', db.removeAction);
 14 
 15 module.exports = router;

Any thoughts on what could be going on here? Thanks in advance.



Solution 1:[1]

If anyone still has issues with this how I solved mine was that I discovered my database was not connected I'm using mongodb for my setup so setting up mongo with the mongod command and running the server again with either node app.js or nodemon app.js fixed mine

Solution 2:[2]

I am also wondering about this statement logged by nodemon. I experienced this only the last days. I get this error if some syntax error exists in my express server code. When I start the server via

> node server

the server does not start and even does not log anything to console. Strange behaviour I think. It seems that this message has nothing to do with nodemon. I never experienced such a thing with node in the past. Every time a syntax error was introduced I got an error message with the stack trace outputted to console.

As I said before it was just a syntax error: A closing bracket was missing from a .then block.

After all I do not know why node was not printing the stack trace as I have experienced it before.

I investigate further but one thing to learn from this kind of error is probably to use a linter for writing javascript code or go a step further and use TypeScript. I use TypeScript for developing the client with Angular and the possibilities to detect syntax errors early are great.

Solution 3:[3]

I too had face the same issue.

Node version was 14.15.5.

so installed node 12.22 version and working fine.

Solution 4:[4]

Facing same problem, I just deleted the node_modules folder and package-lock.json file and reinstalled the dependencies and it worked.

Solution 5:[5]

   app.listen(5010,function(){
      console.log("server is running on port 5010");
   });

// add the code above to resolve this issue

Solution 6:[6]

I had a similar issue after returning to one Node app (main file: app.js) after working on another Node app (main file: index.js).

If I entered

Nodemon app 

I got a message like

[nodemon] starting `node app index.js`
[nodemon] clean exit - waiting for changes before restart

I played around with the version of Nodemon (update made no difference), I then tried entering

Node app

and got the usual proper working response, i.e.

[nodemon] 1.19.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
HTTP server started at port 3000 ...

and I also got it going correctly when I entered

Nodemon app.js 

Now, normally up to then it made no difference whether you enter app.js or app - but here it does seem to make a difference. Maybe some of the cached settings for the other Node app (i.e. the one using index.js as a main script and using app as an object within that file) were being retained and referenced to somehow.

Are there any Nodemon proficient people here to explain this ?

Solution 7:[7]

solution 1:

Firstly make sure you have included these lines of code for the Node-Express application,

 // 3000 is the port number in my case.
    app.listen(3000, function() {
        console.log("Server is running on port " + 3000);
    });

in your main file(i.e. app.js in my case) to start the server.

Solution 2:

Open your package.json file. Check for the name of the file for the main field.
In my case it is {...,"main": "app.js",...}. This app.js is the primary entry point to the program. Now, try to start your server with the following command,

nodemon app.js

or

node app.js

Solution 3:

If your program is running with,

node app.js

but, not with

nodemon app.js

Then, this problem is with nodemon. If you have files with names as index.js and app.js in your project, then deleting index.js will resolve the issue.

If index.js is the entry point to your program, then try Solution 2 given above and change the main field value in the package.json file to index.js i.e. {...,"main": "index.js",...}. This will fix your issue.

Solution 8:[8]

and your program will show the error on browser refused to connect than try this code on terminal if you using express generator

npm start or nodemon start

Solution 9:[9]

After many hours of looking for a solution why my production node-build in docker always immediately stops with exit 0 I found out that the node-version of the docker-images is incompatible. If you face this problem in docker try out different node-versions

Solution 10:[10]

I had the same issue but my problem was very simple newbie issue-adding it here in case those new to express and this type of code make the same mistake

I had unknowingly included the 'app.listen' within my 'app.get' code (yes I know, very basic mistake but it was frustrating, hence giving my option here)

Wrong way

app.get("/", (req, res) => {
    res.send(req.query);
*....additional code here...*
app.listen(port, () => {
    console.log("hey app is listening");
});

});

Right way-

app.get("/", (req, res) => {
    res.send(req.query);
});
app.listen(port, () => {
    console.log("hey app is listening");
});

Solution 11:[11]

[nodemon] starting node index.js URI malformed [nodemon] clean exit - waiting for changes before restart

I was able to fix this by changing the '@' symbol in my password for the connection url to %40

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Neo09
Solution 2
Solution 3 Sayeed roshan
Solution 4 Pradeep
Solution 5 Okpo
Solution 6 Trunk
Solution 7
Solution 8 Amir Khan
Solution 9 Matthias Gruba
Solution 10 Snowcat
Solution 11 Leelo