Published on

How to Deploy Node.js on AWS in Under 15 Minutes

Deploying a Node.js application on AWS (Amazon Web Services) can be completed in under 15 minutes using AWS App Runner, a service that handles server management for you. By connecting a GitHub repository to App Runner, your code automatically builds and goes live with a secure URL. This method allows you to scale from zero to thousands of users without manually configuring virtual servers.

What is the best way for beginners to launch on AWS?

While AWS offers over 200 services, beginners should focus on AWS App Runner. It is a "fully managed" service, which means Amazon takes care of the underlying infrastructure, security updates, and scaling. You do not need to learn how to manage an OS (Operating System) or configure complex networking rules.

In our experience, starting with App Runner prevents the "configuration fatigue" that often stops new developers from finishing their projects. It provides a straight path from your local computer to a live website. This approach is much simpler than using EC2 (Elastic Compute Cloud), which requires you to set up your own virtual computer from scratch.

What tools do you need before starting?

Before you begin the deployment process, you must have a few specific items ready. These ensure that the AWS cloud can read your code and run it properly.

  • An AWS Account: You will need a verified account at aws.amazon.com.
  • GitHub Account: Your code should be stored in a GitHub repository (a central folder for your code online).
  • Node.js 22+: Ensure your local environment uses a modern version of Node.js (the runtime that executes JavaScript on a server).
  • A Simple App: A basic "Hello World" application using a framework like Express.js (a popular tool for building web servers).

How do you prepare your Node.js code?

Your application needs a clear set of instructions so AWS knows how to start it. This is handled by the package.json file in your project folder. Ensure your file includes a "start" script that points to your main entry file.

// package.json example
{
  "name": "my-aws-app",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js" // This tells AWS how to run your app
  },
  "dependencies": {
    "express": "^5.0.0" // Using the latest stable Express version
  }
}

You also need to make sure your app listens on a port (a communication endpoint) that AWS can access. Most cloud services expect your app to listen on a variable called PORT.

// index.js example
const express = require('express');
const app = express();
const port = process.env.PORT || 3000; // AWS will provide the PORT automatically

app.get('/', (req, res) => {
  res.send('My Node.js app is live on AWS!');
});

app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

How do you set up AWS App Runner?

Log in to your AWS Management Console and search for "App Runner" in the top search bar. Click the "Create an App Runner service" button to begin the setup wizard.

First, select "Source code repository" as your source. You will need to click "Add new" to connect your GitHub account to AWS. Follow the prompts to authorize AWS to see your code repositories.

Next, select the specific repository and branch (usually "main") you want to deploy. In the "Deployment settings" section, choose "Automatic." This means every time you push new code to GitHub, AWS will update your live site.

What are the build and runtime settings?

AWS needs to know what "engine" to use to run your code. Select "Node.js 18" or "Node.js 20" (or the latest available version in the dropdown) as the runtime.

For the "Build command," type npm install. This command tells AWS to download all the libraries your app needs to function.

For the "Start command," type npm start. This matches the script we created earlier in your package.json file. Finally, set the "Port" to 3000 or whichever number your code uses.

What should you see after clicking deploy?

After you click "Create & Deploy," AWS will start the "provisioning" process. This is when the service sets up the hardware and software needed to host your app.

You will see a status screen with a spinning icon and a log window. The logs will show AWS downloading your code and installing your dependencies.

Once the status changes to a green "Running" checkmark, AWS will provide a "Default domain." This is a URL ending in .awsapprunner.com. Click that link to see your live Node.js application in your browser.

What are common mistakes to avoid?

One common error is forgetting to set the PORT correctly. If your code is hard-coded to port 8080 but App Runner is looking at port 3000, the site will not load. Always ensure the port in your AWS settings matches the port in your JavaScript code.

Another mistake is missing the .gitignore file. You should never upload your node_modules folder to GitHub. AWS will install those files itself during the build process, and uploading them manually makes the deployment very slow.

Lastly, watch your "Region" settings. We suggest picking a region close to you, like us-east-1 (North Virginia) or eu-west-1 (Ireland). This helps reduce the time it takes for you to access the AWS console and your app.

Next Steps

Now that your app is live, you can try adding a custom domain name or connecting a database. AWS offers a service called RDS (Relational Database Service) for storing user data. You might also want to explore adding environment variables (secret keys) in the App Runner configuration to keep your API keys safe.

Don't worry if the first deployment takes a few minutes to finish. It is normal to see a few "Health check" retries while the server starts up for the first time. Once you master this workflow, you can deploy new features simply by saving your code and pushing it to GitHub.

For detailed guides, visit the official Node.js documentation.


Read the Node.js Documentation