This guide hosts a tiny Node.js website on Amazon EC2 using only the built-in http module—no frameworks—then keeps it online with PM2.
What is a vanilla Node.js site on EC2?
Node can answer HTTP with http.createServer. On Ubuntu EC2 you upload a few files, open port 80 in the security group, and run the process under PM2 so it survives SSH disconnects.
When should you use this approach?
Use it to learn EC2 networking, SFTP, and process management with the smallest possible app. When routes and middleware grow, move to Express.js on EC2 or a full stack such as Next.js on EC2.
What you will build
Two files (index.js + hello-world.html), uploaded with FileZilla, started with pm2 start index.js, and opened via the public DNS or Elastic IP.
Tools in this walkthrough
PuTTY (or SSH), Node.js and npm on Ubuntu, FileZilla for SFTP, and PM2 as the process manager.
No npm project required.
This sample uses only Node built-ins (http, fs, path). You still install PM2 with npm.
Avoid chmod 777 in production.
Wide-open permissions are only for a quick FileZilla demo. Prefer chown for your deploy user afterward.
Port 80 is privileged.
Listening on 80 usually needs elevated privileges. Production often uses a high port behind Nginx or an ALB on 80/443.
Most “site won’t load” issues are security groups, port privileges, or a missing HTML file path.
port
EACCES on port 80
Non-root processes cannot bind low ports. Use sudo pm2 start for demos, or listen on 3000+ behind a proxy/ALB.
sg
Security group blocks HTTP
Inbound TCP 80 must allow your client. SSH still needs TCP 22.
path
500 on /hello-world
Usually the HTML file is missing or not next to index.js. Check the upload path and __dirname.
pm2
App dies after reboot
pm2 start alone does not survive reboot. Use pm2 startup / pm2 save when you want auto-start.
perms
Leaving chmod 777 forever
World-writable app dirs are a security risk. Fix ownership after FileZilla uploads.
scale
Manual if/else routing gets messy
When you need many routes or middleware, graduate to Express.
Remember
Key Takeaways
Start small:http.createServer is enough to learn EC2 + PM2.
PM2: keeps Node running after SSH disconnect; open the right security group ports.
Permissions: prefer chown over lasting 777.
Next level: Express, HTTPS, and a reverse proxy/ALB for real apps.
One line: upload two files, pm2 start index.js, open port 80, then harden for production.
Frequently Asked Questions
PM2 keeps your Node process running after you close SSH, can restart it on crashes, and can hook into system startup. For a single EC2 instance it is a simple alternative to writing a systemd unit by hand.
Port 80 is the default HTTP port so you can test with http://your-ip/ without a port suffix. On Linux, ports below 1024 are privileged, so the example uses sudo with PM2. Production setups often use a high port plus Nginx on 80/443.
Use Express or another framework when you need cleaner routing, middleware, body parsing, and a large ecosystem. The http module is fine for tiny demos.
No. The sample uses only Node built-ins (http, fs, path). You still need Node installed on the instance, and PM2 is installed globally with npm.
No. It is only a quick demo shortcut for SFTP writes. Prefer chown for your deploy user and tight permissions afterward.
Add HTTPS (ACM + ALB or a reverse proxy), pm2 startup on reboot, monitoring, and move to Express or Next when routing grows.