1

Iam using this command : npm run server

I've been looking for a solution to this but don't know why the results still don't work. I've tried installing it globally npm install -g nodemon but still not restarting automatically only gets posts like this :

i got this not only in file Validations\register.js

[nodemon] files triggering change check: validations\register.js [nodemon] matched rule: ***.* [nodemon] changes after filters (before/after): 1/1 [nodemon] restarting due to changes... [nodemon] Validations\register.js

Package.json

{
  "name": "devconnector",
  "version": "1.0.0",
  "description": "express react",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "server": "nodemon server.js --verbose"
  },
  "author": "Faris Dewantoro",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "express": "^4.16.4",
    "gravatar": "^1.6.0",
    "jsonwebtoken": "^8.3.0",
    "mongoose": "^5.3.4",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "validator": "^10.8.0"
  },
  "devDependencies": {
    "nodemon": "^1.17.3"
  }
}

Server.js

const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');

// ROUTER
const users = require('./routes/api/users');
const profile = require('./routes/api/profile');
const posts = require('./routes/api/posts');

const app = express();

app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());

// DB Config
const db = require('./config/keys').mongoURI;

// Connect to MongoDB
mongoose
    .connect(db,{ useNewUrlParser: true })
        .then(()=>{
            console.log('MongoDB Connected');
        })
        .catch((err)=>{
            console.log(err);
        });

// Passport middleware
app.use(passport.initialize());
// Passport Config
require('./config/passport')(passport);
// User routes
app.use('/api/users',users);
app.use('/api/profile',profile);
app.use('/api/posts',posts);

const port = process.env.PORT || 5000;

app.listen(port,()=>{
    console.log(`Server running on port ! ${port}`);
});

how to fix this so that the nodemon can restart the server automatically

Note : Iam using Windows 10 Pro 2018 64x

Update I tried with code like this and the results remained the same :

const express = require('express');

const app = express();

const port = process.env.PORT || 5000;

app.listen(port,()=>{
    console.log(`Server running on port   ${port}`);
});

[nodemon] 1.17.3 [nodemon] to restart at any time, enter rs [nodemon] or send SIGHUP to 10316 to restart [nodemon] watching: . [nodemon] watching extensions: js,mjs,json [nodemon] starting node server.js [nodemon] forking [nodemon] child pid: 18172 [nodemon] watching 13 files Server running on port ! 5000

When i changed console.log(Change testing ${port});

[nodemon] files triggering change check: server.js
[nodemon] matched rule: ***.* [nodemon] changes after filters (before/after): 1/1 [nodemon] restarting due to changes...
[nodemon] Server.js

Faris Dewantoro
  • 1,597
  • 4
  • 17
  • 31
  • any more logs after the line `[nodemon] Validations\register.js` ? – Neverever Oct 19 '18 at 03:45
  • no but its not restarting the server @Neverever – Faris Dewantoro Oct 19 '18 at 03:47
  • @FarisDewantoro can you try pm2 (https://github.com/Unitech/pm2) or browser-refresh(https://github.com/patrick-steele-idem/browser-refresh). If you see similar behavior then there is an issue with your code. I don't have all your code so i am not sure where the issue might be. Also is your app running fine? Usually if you app throws error nodemon breaks. – РАВИ Oct 19 '18 at 03:55
  • `nodemon` works perfectly for me, I think you need to minimise the code, try removing all the routes, mongodb and middlewares, leave only the express, and try updating different files (sub-files or server.js itself) – Neverever Oct 19 '18 at 03:56
  • an issue I've had with nodemon in the past is that an old process doesn't fully get killed so you have a ghost process listening on a port. When nodemon tries to restart it fails because there already is a process listening on that port. Is it possible that might be the case? – ns_helloworld Oct 19 '18 at 03:59
  • @ns_helloworld you're right, I'm not running nodemon but the server is still running, how do I turn it off? – Faris Dewantoro Oct 19 '18 at 05:41
  • I have turned it off but the results are the same, it still does not restart the server automatically @ns_helloworld – Faris Dewantoro Oct 19 '18 at 05:50

1 Answers1

0

Package.json

{
  "name": "devconnector",
  "version": "1.0.0",
  "description": "express react",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "server": "nodemon server.js"
  },
  "author": "Faris Dewantoro",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "express": "^4.16.4",
    "gravatar": "^1.6.0",
    "jsonwebtoken": "^8.3.0",
    "mongoose": "^5.3.4",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "validator": "^10.8.0"
  },
  "devDependencies": {
    "nodemon": "^1.17.3"
  }
}

Change the script tag
It's get work :)

ANAGH K R
  • 114
  • 1
  • 4