I'm trying to move an existing node.js express app from Heroku to AWS. The app uses MongoDB for the database. The problem is aws EB (Elastic Beanstalk) doesn't natively support no-sql databases (I understand that I need to use a VPC and am able to connect a VPC to MongoDB). I'm a little confused with setup both on the app's code (how the config files should be written/if any backend changes that might be needed), and how it should be setup in AWS. Is there a better option for this? Right now eb deploy fails and the logs don't seem helpful. Any advice is greatly appreciated.
config.yml
branch-defaults:
Master:
environment: Testproject-env
environment-defaults:
Testproject-env:
branch: null
repository: null
global:
application_name: test-project
default_ec2_keyname: null
default_platform: Node.js
default_region: us-east-2
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
sc: git
workspace_type: Application
nodecommand.config
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
app.js
const express = require("express");
const mongoose = require('mongoose');
const users = require('./routes/api/users');
const bodyParser = require('body-parser');
const passport = require('passport');
const path = require('path')
const app = express();
if (process.env.NODE_ENV === 'production') {
app.use(express.static('frontend/build'));
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, 'frontend', 'build', 'index.html'));
})
}
const db = require('./config/keys_dev').mongoURI;
mongoose
.connect(db, { useNewUrlParser: true })
.then(() => console.log("Connected to MongoDB successfully"))
.catch(err => console.log(err));
app.use(passport.initialize());
require('./config/passport')(passport);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/api/users', users);
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server is running on port ${port}`));