Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Task 01 - Create a Sample Node.js Application

Introduction

In this Task, the goal is to create a sample Node.js application to serve as a sample workload that can be used to migrate to AKS.

Description

After you complete this task, you will be able to:

  • Create a sample Node.js application
  • Validate the application works correctly

Success Criteria

  • Successfully test the Node.js application

Requirements

You will use your own Windows 10 or Windows 11 local machine to simulate the creation of the workload to containerize and deploy to AKS. Make sure the following resources are installed on your local machine

Solution

Expand this section to view the solution

Create a simple Node.js application

You will create a Node.js + Express to establish an easy, standard and quick workload to use as for migrating to AKS later.

  1. Create a folder and name it aks_demo_app on your local machine

    IMPORTANT: You must run Docker Desktop on your local machine to complete this task.

  2. From your terminal, change directory to this empty folder
  3. Create a new file in the directory and name it app.js
  4. Copy the following code to the app.js file

     const express = require('express');
     const app = express();
    
     app.get('/', (req, res) => {
       res.send('Hello from Secure Workload Migration Workshop');
     });
    
     const port = 3000;
     app.listen(port, () => {
       console.log(`App running on port ${port}`);
     });
    
  5. Create a new file in the folder and name it package.json
  6. Copy the following to the package.json file

     {
       "name": "aks-demo",
       "version": "1.0.0",
       "main": "app.js",
       "dependencies": {
         "express": "^4.18.2"
       }
     }
    
  7. From the terminal at the aks_demo_app directory, run the following to install the required npm dependencies:

     npm install
    

    If you don’t have npm installed, please find the download and setup instructions here

  8. After the dependencies are installed, run the following command to start the application:

     node app.js
    
  9. To verify the app is running, open your browser and navigate to [http://localhost:3000/](http://localhost:3000/). You should see a similar result as the the screenshot below:

    node.js app running

  10. Stop the application by going back to the terminal and pressing CTRL + C.