简体   繁体   中英

node server not running - throwing process.nextTick(function() { throw err; })

I am trying to run node express in c9.io but I am having problem it gives me this error I can't figure it out. I am getting this error message.

$ node app.js
Server is running

/home/ubuntu/workspace/RESTful Routing/RESTfulBlogApp/node_modules/mongodb/lib/server.js:242
        process.nextTick(function() { throw err; })
                                      ^
Error: getaddrinfo ENOTFOUND localhost.restful_blog_app localhost.restful_blog_app:27017
    at errnoException (dns.js:27:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)

var bodyParser = require("body-parser"),
mongoose       = require("mongoose"),
express        = require("express"),
app            = express();

    mongoose.connect("mongodb://localhost.restful_blog_app");
    app.set("view engine", "ejs");
    app.use(express.static("public"));
    app.use(bodyParser.urlencoded({extended: true}));

    app.listen(process.env.PORT, process.env.IP, function(){
       console.log("Server is running"); 
    });

我认为是mongoose.connect("mongodb://localhost/restful_blog_app");

You should also remember to start the database before running the server. And in case you still have issues, you should try to change localhost into 127.0.0.1 instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM