gpt4 book ai didi

javascript - MongoError : failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFU SED 127. 0.0.1:27017]

转载 作者:行者123 更新时间:2023-11-28 04:22:58 26 4
gpt4 key购买 nike

我的问题是关于 mongo 未连接到服务器?为什么它说在第一次连接时无法连接到服务器 [localhost:27017] [MongoError: connect ECONNREFUSED 127.0.0.1:27017]

Here is my code:
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose");


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

app.get('/', function (req, res) {
res.send('Hello World!')
});

app.listen(3000, function () {
console.log('Example app listening on port 3000!')
});

最佳答案

在您的计算机上安装 mongodb(如果您使用的是 Mac,请运行 brew install mongodb),然后打开一个新终端,运行 mongod,然后重新启动你的应用程序

关于javascript - MongoError : failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFU SED 127. 0.0.1:27017],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45302814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com