process.nextTick(function() throw err; ) 错误:getaddrinfo ENOTFOUND 节点节点:27017 - nodejs
Posted
技术标签:
【中文标题】process.nextTick(function() throw err; ) 错误:getaddrinfo ENOTFOUND 节点节点:27017 - nodejs【英文标题】:process.nextTick(function() throw err; ) rror: getaddrinfo ENOTFOUND noder noder:27017 - nodejsprocess.nextTick(function() throw err; ) 错误:getaddrinfo ENOTFOUND 节点节点:27017 - nodejs 【发布时间】:2016-12-02 20:06:41 【问题描述】:当我第一次点击http://localhost:8080 时,它给了我正确的响应,但也显示以下错误。当再次点击 http://localhost:8080 时,我在 UI 上什么也看不到。
D:\node_workspace\node-token-jwt\node_modules\mongodb\lib\server.js:242
process.nextTick(function() throw err; )
^
Error: getaddrinfo ENOTFOUND noder noder:27017
at errnoException (dns.js:27:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)
我正在使用 node.js。我该如何解决这个问题?
server.js
// get the packages
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var morgan = require('morgan');
var mongoose = require('mongoose');
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
var config = require('./config'); // get our config file
var User = require('./app/models/user'); // get our mongoose model
var port = process.env.PORT || 8080; // used to create, sign, and verify tokens
mongoose.connect(config.database); // connect to database
app.set('superSecret', config.secret); // secret variable
// use body parser so we can get info from POST and/or URL parameters
app.use(bodyParser.urlencoded( extended: false ));
app.use(bodyParser.json());
// use morgan to log requests to the console
app.use(morgan('dev'));
app.get('/', function(req, res)
res.send('Hello! The API is at http://localhost:' + port + '/api');
);
app.listen(port);
console.log('Magic happens at http://localhost:' + port);
user.js
// get an instance of mongoose and mongoose.Schema
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// set up a mongoose model and pass it using module.exports
module.exports = mongoose.model('User', new Schema(
name: String,
password: String,
admin: Boolean
));
config.js
module.exports =
'secret': 'ilovescotchyscotch',
'database': 'mongodb://noder:noderauth&54;proximus.modulusmongo.net:27017/test'
;
package.json
"name": "node-token-jwt",
"main": "server.js",
"dependencies":
"body-parser": "^1.15.2",
"express": "^4.14.0",
"jsonwebtoken": "^7.1.6",
"mongoose": "^4.5.7",
"morgan": "^1.7.0"
【问题讨论】:
你确定这是整个错误信息吗?堆栈跟踪将有助于了解错误的来源。 是的,这是完整的堆栈跟踪!! 27017 是标准的 mongoDB 端口,你确定要用套接字连接它吗?那个 mongoDB 已经启动并正在监听?把 mongoDB 放到 localhost 能用吗? 嘿,我也遇到了同样的错误。如果您能够解决,这是我的错误。那么请也看看我的错误。我的数据库在线。 【参考方案1】:Mongodb 好像没有运行
试试
输入“mongod”然后重启服务器
【讨论】:
以上是关于process.nextTick(function() throw err; ) 错误:getaddrinfo ENOTFOUND 节点节点:27017 - nodejs的主要内容,如果未能解决你的问题,请参考以下文章
process.nextTick 和 queueMicrotask 的区别
Node.js 中 process.nextTick 的正确用例是啥?
process.nextTick,Promise.then,setTimeout,setImmediate执行顺序