Node.js nodejs mongoose在部署到aws并在本地计算机上工作时显示错误
一个nodejs项目,在使用CodePipeline和github在aws上部署时显示错误,但在本地计算机上运行时工作正常 错误-Node.js nodejs mongoose在部署到aws并在本地计算机上工作时显示错误,node.js,github,mongoose,amazon-elastic-beanstalk,aws-codepipeline,Node.js,Github,Mongoose,Amazon Elastic Beanstalk,Aws Codepipeline,一个nodejs项目,在使用CodePipeline和github在aws上部署时显示错误,但在本地计算机上运行时工作正常 错误- mongoose .connect( "mongodb+srv://node-sandbox:" + process.env.MONGO_ATLAS_PW + "@node-sandbox-2hdom.mongodb.net/test?retryWrites=true&w=majority&quo
mongoose
.connect(
"mongodb+srv://node-sandbox:" +
process.env.MONGO_ATLAS_PW +
"@node-sandbox-2hdom.mongodb.net/test?retryWrites=true&w=majority",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
}
)
.catch((err) => {
console.log("printing mongoose error - " + err);
});
mongoose.Promise = global.Promise;
编辑:
我是后端开发新手。
尝试通过邮递员连接时收到此响应-
printing mongoose error - MongoError: bad auth Authentication failed.
printing mongoose error - MongooseServerSelectionError: bad auth Authentication failed.
connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.37.102, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "172.31.8.154"
502坏网关
502坏网关
nginx/1.16.1
我不认为mongo连接有任何问题,在mongo控制台中,它显示的是一个连接,只能是这个连接。所以还有其他问题!找不到问题!
可能是http/https问题。我处理的是同样的问题,我必须添加我的应用程序在buildspec.yml中运行所需的文件 当它失败时,我的buildspec.yml文件在artifacts部分只有下面的代码:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
我修复了添加node_模块的问题/**/*
artifacts:
files:
- app.js
- package.json
我在处理同样的问题,我必须添加我的应用程序在buildspec.yml中运行所需的文件 当它失败时,我的buildspec.yml文件在artifacts部分只有下面的代码:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
我修复了添加node_模块的问题/**/*
artifacts:
files:
- app.js
- package.json
代码看起来不错,你确定process.env.MONGO_ATLAS_PW在AWS上有正确的值吗?有一段时间我在githhub中也添加了.env文件,这样环境变量将与开发时的环境变量相同。但它仍然不起作用。在aws上添加环境变量还有其他方法吗@chcamiloam代码看起来不错,你确定process.env.MONGO_ATLAS_PW在AWS上有正确的值吗?有一段时间,我在githhub中也添加了.env文件,这样环境变量将与开发相同。但它仍然不起作用。在aws上添加环境变量还有其他方法吗@切卡米洛姆