【发布时间】:2018-09-15 20:23:10
【问题描述】:
我正在尝试在我的终端中运行 nodemon index.js,但我收到以下错误,我完全不知道这对我来说意味着什么非常不清楚。
谁能告诉我如何解决这个问题?
index.js
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
var app = express();
var router = require('./services/router');
mongoose.connect('mongodb://localhost:apiAuth');
app.use(morgan('combined'));
app.use(bodyParser.json());
app.use('/v1', router);
var PORT = process.env.PORT || 3000;
var HOST = process.env.HOST || '127.0.0.1';
console.log('Listening on', HOST, PORT);
app.listen(PORT, HOST);
services/router.js
var router = require('express').Router();
function protected(req, res, next) {
res.send('Here is the secret!');
}
router.route('/protected')
.get(protected);
module.exports = router;
终端
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Listening on 127.0.0.1 3000
(node:29104) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Slash in host identifier
(node:29104) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
-
尝试将
app.use('/v1', router);更改为app.use('v1', router); -
@wayneOS 还是一样的错误
-
如指出从 v1 中删除
/和从/protected中删除看起来不正确,可能尝试从中删除/ -
@Jaya 没有任何变化
-
我试图删除路由器,直到保持不变
标签: javascript mongodb nodemon