Nodemon不重新启动:[nodemon]由于更改而重新启动

时间:2018-10-19 03:26:44

标签: javascript node.js express npm nodemon

我正在使用以下命令:npm run server

我一直在寻找解决方案,但是不知道为什么结果仍然不起作用。我尝试在全局npm install -g nodemon上安装它,但仍然不能自动重启,只会得到像这样的帖子:

我不仅在Validations \ register.js文件中得到了

  

[nodemon]文件触发更改检查:validations \ register.js   [nodemon]匹配的规则:***。* [nodemon]在过滤器之后发生更改   (之前/之后):1/1 [nodemon]由于更改而重新启动... [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}`);
});

如何解决此问题,以便nodemon可以自动重新启动服务器

注意: 使用Windows 10 Pro 2018 64x的Iam

更新 我尝试使用这样的代码,结果保持不变:

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]要随时重新启动,请输入rs   [nodemon]或将SIGHUP发送到10316以重新启动[nodemon]监视:   [nodemon]观看扩展:js,mjs,json [nodemon]开始node server.js [nodemon]分叉[nodemon]子pid:18172 [nodemon]   观看13个文件服务器在端口上运行! 5000

当我更改了console.log(更改测试$ {port} );

  

[nodemon]文件触发更改检查:server.js
    [nodemon]匹配的规则:***。*     [nodemon]在过滤器之后(之前/之后)更改:1/1   [nodemon]由于更改而重新启动...
    [nodemon] Server.js

0 个答案:

没有答案