Deploy Node.js application using Exopods

We will guide you through the process of creating a Node.js application, containerising it using Docker, and deploying it effortlessly with Exopods. By the end of this guide, you'll have a live Node.js application running in the cloud.

Prerequisites

Before we begin, make sure you have the following installed on your computer:

Creating a Node.js Application and Docker Image

1. Initialize a New Node.js Project

  • Open your terminal or command prompt.

  • Navigate to the directory where you want to create your project.

  • Run the following command to initialize a new Node.js project:

    npm init -y

    This will create a package.json file with default settings.

2. Install Express.js

  • Install Express.js, a popular web framework for Node.js, using npm:

    npm install express

3. Create an index.js File

  • Create a new file named index.js in your project directory.

  • Add the following code to index.js:

    const express = require('express');
    const app = express();
    
    app.get('/', (req, res) => {
        res.send('Hello, World!');
    });
    
    app.listen(3000, () => {
        console.log('Server listening on port 3000');   
    });

4. Update package.json

  • Open the package.json file and add a start script:

    "scripts": {
        "start": "node index.js"
    }

5. Create a Dockerfile

  • Create a new file named Dockerfile in the root of your project directory.

  • Add the following content to Dockerfile:

    FROM node:16-alpine
    
    WORKDIR /usr/src/app
    
    COPY package*.json ./
    
    RUN npm install
    
    COPY . .
    
    CMD ["npm", "start"]

6. Build and Push the Docker Image to Docker Hub

  • Build the Docker image:

    docker build -t my-node-app .

    Replace my-node-app with your desired image name.

  • Log in to Docker Hub:

    docker login

    Enter your Docker Hub username and password.

  • Push the Docker image:

    docker push my-node-app
  • Copy the image URL:

    You can find the image URL on Docker Hub. It will be in the format your-docker-hub-username/my-node-app

Configure Your Deployment on Exopods

Now, we will set up the deployment configuration in Exopods. This involves specifying the container’s name, image URL, port, and other configurations.

  1. Navigate to the deployment configuration page on Exopods.

  2. Fill in the required details:

  3. Container Name.

  4. Docker Image Repo URL.

  5. Port.

  6. Environment Variables.

  7. Arguments.

Deploy and Obtain Your Public URL

Finally, deploy your configured application and get a public URL within seconds.

  1. Click the Deploy button on the Exopods interface.

  2. Wait for the deployment process to complete (usually about 5 seconds).

  3. Note the public URL provided by Exopods for your application.

Conclusion

You’ve successfully deployed your Node.js application using Docker and Exopods. Thank you for following along, and happy deploying!

Last updated