I am currently trying to deploy a node js app on an AWS EC2 Windows Server 2019 instance. I am done with cloning my git repo and starting up my application and can access it within my EC2 instance.
To make my node application accessible I used the Internet Information Services (IIS) Manager and added the app under Default Web Site. I added the URL Rewrite module and added an inbound rule like so:
I can access the EC2 instance via its "Public DNS (IPv4)", which shows the default IIS Template: http://ec2-13-58-250-47.us-east-2.compute.amazonaws.com
But as soon as I add something to the path such as "/app", ":3000/app" or "/app:3000" I received "500" or "404" errors. What would be the correct path to access my app?
Other things I tried:
Security Groups
I googled a bit and most threads suggest checking the security group for the EC2 instance, which is what I have done. Here is a screenshot of my current security group:
Port
My .env file does not contain a PORT, which is why I expect the app to use the hard-coded port 3000. To make sure i printed the port via listener.address().port
and it uses 3000.
The app.js file looks like this:
const express = require("express")
const path = require("path")
const router = require("./router/auth.routes")
const bodyParser = require("body-parser")
const cookieParser = require("cookie-parser")
const passport = require("passport")
const winston = require('./config/winston')
const { initialiseAuthentication } = require("./auth")
const { connectToDatabase } = require("./database/connection")
require("dotenv").config()
/**
* App Variables
*/
const app = express()
const port = process.env.PORT || 3000
/**
* App Configuration
*/
app.use(compression())
app.set("views", path.join(__dirname, "views"))
app.set("view engine", "pug")
app.use(express.static(path.join(__dirname, "public")))
app.use(express.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(passport.initialize())
initialiseAuthentication(app)
/**
* Routes Definition
*/
app.use('/', router)
async function establishConnection() {
await connectToDatabase()
.then(() => winston.log('info', 'Connection to database established.'))
.catch(err => {
winston.log('warn', 'Retrying')
setTimeout(establishConnection, 2000)
})
}
/**
* Server Activation
*/
app.listen(port, () => {
establishConnection()
})
Any suggestions? I am currently stuck here as this is the first time for me setting up an EC2 instance and with a nodejs app.