[英]NodeJS API with DynamoDB - Missing region in config but it is set
I created a NodeJS API and when I start my server, I can do my HTTP requests with success to my AWS Dynamo DB. 我创建了一个NodeJS API,当我启动服务器时,我可以成功地向我的AWS Dynamo DB发出HTTP请求。 But about twenty seconds after the request's response, the server crashes and says "missing region in config"
但是在请求响应后大约二十秒钟,服务器崩溃并显示“配置中缺少区域”
My requests are successful so why does it do that ? 我的请求成功了,为什么要这么做呢?
This is my server.js
: 这是我的
server.js
:
const express = require('express');
const config = require('./config');
const cors = require('cors');
const createError = require('http-errors');
const bodyParser = require('body-parser');
const app = express();
// parse requests
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
//Enable CORS for all HTTP methods
app.use(cors());
// Routes
require('./routes/survey.route.js')(app);
require('./routes/user.route.js')(app);
// Handle defaut request without any route or params
app.get('/', (request, response) => {
response.send("Welcome to my API !");
});
// Listen on port 8080 for connections
app.listen(config.serverPort, (err) => {
if (err) {
return console.log('something bad happened', err);
}
console.log(`server is listening on ${config.serverPort}`);
});
// catch 404 and forward to error handler
app.use(function(req, res, next) {
console.log(req);
next(createError(404));
});
module.exports = app;
Each of my routes' requests include the file database.js
我的每条路线请求都包含文件
database.js
Which has code : 里面有代码:
// Configuring the database
const AWS = require('aws-sdk');
const config = require('./config');
AWS.config.update({
accessKeyId: config.aws_accessKeyId,
secretAccessKey: config.aws_secretAccessKey,
region: config.aws_region
});
And this is my config.js
: 这是我的
config.js
:
module.exports = {
baseUrl: '/api',
serverPort: 8080,
aws_accessKeyId: 'XXXXX',
aws_secretAccessKey: 'XXXXX',
aws_region: "us-east-2"
};
module.exports = AWS;
I can't find why my app crashes in both local and EC2 instance... 我找不到为什么我的应用程序在本地实例和EC2实例中都崩溃的原因...
Haven't been able to fix this since few days of searches 搜索几天后一直无法解决此问题
通过从头开始创建新项目并删除dynamoose进行了修复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.