Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 227
cosmicluna Avatar asked Jan 31 '18 04:01

cosmicluna


People also ask

How do I stop Nodemon from running in the background?

For purposes of completeness, The correct answer is press Ctrl + C . Or you could also find it in task manager and kill it. This applies to pretty much anything on the command line.

Does Nodemon restart on crash?

Nodemon monitors your source files for changes during development and reload on change. That's why it says 'waiting for file change' after a crash. In development, usually you made a mistake, correct it, save the source file, nodemon notices that and reloads.

How do I manually restart Nodemon?

Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.

Why Nodemon is not working?

Use npx to solve the error "'nodemon' is not recognized as an internal or external command, operable program or batch file", e.g. npx nodemon server. js or install the package globally by running npm install -g nodemon and make sure your PATH environment variable is set up correctly.


1 Answers

There are a few things wrong with your code. You never told your app to run. When you're ready creating your routes you should start your server with:

app.listen(<port on which the server should run here>);

Also you have an Express app and a router in the same file. The router should only be used as a sub module (handy when you want to divide your app over multiple files). Right now you're doing nothing with it. If you remove the router and the export then it should work fine.

like image 117
Kamil Kulach Avatar answered Sep 20 '22 16:09

Kamil Kulach