我已经安装了Nodemon和Mongodb,并试图使两者连接。但是,每当我运行Mongod时,它总是挂在“等待端口27017上的连接”,并且不会识别Nodemon。例如,如果我停止Nodemon服务器,它将无法识别它。如何确保Nodemon和Mongod相互识别。
我的index.js文件如下所示:
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const router = require('./router');
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:auth/auth')
app.use(morgan('combined'));
app.use(bodyParser.json({ type: '*/*' }));
router(app);
const port = process.env.PORT || 3090;
app.listen(port)
// server.listen(port);
console.log('Server listening on port:', port)
router.js文件如下:
module.exports = function(app) {
app.get('/', function(req, res, next) {
res.send(['watterbottle', 'phone', 'paper'])
});
}