node.js - process.nextTick(function() { throw err; }) rror: getaddrinfo ENOTFOUND noder noder:27017 - nodejs -
when first time hit http://localhost:8080, gives me correct response, shows below error too. when again hit http://localhost:8080, see nothing on 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 @ errnoexception (dns.js:27:10) @ getaddrinforeqwrap.onlookup [as oncomplete] (dns.js:78:26)
i using node.js. how can fixed ?
server.js
// 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 create, sign, , verify tokens var config = require('./config'); // our config file var user = require('./app/models/user'); // our mongoose model var port = process.env.port || 8080; // used create, sign, , verify tokens mongoose.connect(config.database); // connect database app.set('supersecret', config.secret); // secret variable // use body parser can info post and/or url parameters app.use(bodyparser.urlencoded({ extended: false })); app.use(bodyparser.json()); // use morgan log requests console app.use(morgan('dev')); app.get('/', function(req, res) { res.send('hello! api @ http://localhost:' + port + '/api'); }); app.listen(port); console.log('magic happens @ http://localhost:' + port);
user.js
// instance of mongoose , mongoose.schema var mongoose = require('mongoose'); var schema = mongoose.schema; // set mongoose model , pass 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" } }
Comments
Post a Comment