Publish a Node.js App to Axway’s ARS

You may be aware that you can easily publish your API Builder project to Axway’s AMPLIFY Runtime Service (ARS) using this guide. However, did you know that you can publish a non API Builder Node.js app to ARS as well?

You can! This blog post will show you how, using a simple Node.js Express app.

You can download the assets for this project here.

Setup and Test Node App Locally

Let’s create a simple Node.js Express app locally on your machine and test it as follows:

  • Copy index.js and package.json files to a project folder (e.g. simplenodeapp)

* index.js

const express = require("express");
const app = express();
app.get("/", (req, res) => {
  res.send("Hello Node/Express App!!!");
});
app.listen(4001, () => {
  console.log("listening on port 4001");
});

* package.json

{
  "dependencies": {
    "express": "*"
  },
  "scripts": {
    "start": "node index.js"
  }
}
  • Use terminal to run the following in your project folder to install dependencies:
npm install
  • Run your project using:
npm start

You should see a response similar to:

  • Go to ‘localhost:4001’ in your browser and see “Hello Node/Express App!!!” message

Create Docker Image and Test Locally

Now that we have a working Node.js app, we need to create a docker image in order to publish it to ARS.

  • Copy the Dockerfile into your project folder:

* Dockerfile

FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
CMD ["npm","start"]
  • Create a docker image using the following command in terminal in your project folder:
docker build -t simplenodeapp:latest .
  • Check that your Docker image was created using:
docker image ls

See simplenodeapp at the top of the list above

  • Run your Docker image as a container using:
docker run --rm -p 80:4001 simplenodeapp
  • Check to see your running container using:
docker ps -a
  • Go to ‘localhost:4001’ in your browser and see “Hello Node/Express App!!!” message as before

Publish to ARS and Test

Now that we have a working Node.js app in a docker image, we can publish to ARS.

Note that we are roughly following the instruction here but we’re not publishing an API Builder app, we’re publishing a Nodejs app

  • Create an ARS app using the following:
amplify acs login
amplify acs new simplenodeapp --force
amplify acs config --set PORT=4001 simplenodeapp
amplify acs server --set Medium simplenodeapp
  • Publish Docker Image to ARS using:
amplify acs publish simplenodeapp --delete_oldest --force --image simplenodeapp --app_version 0.1

Note: Ignore healthcheck warning

  • See message with base URL of your published app similar to below:

App simplenodeapp version 0.1 published.
App will be available at https://{guid}.cloudapp-enterprise.appcelerator.com

  • Check the status and logs of your app using:
amplify acs list simplenodeapp
amplify acs logcat simplenodeapp
  • Once the app is deployed and running, go to https://{guid}.cloudapp-enterprise.appcelerator.com in browser and see the “Hello Node/Express App!!!” message

Note that if you modify your Node app and want to publish a new version, you can use the following command:

amplify acs publish simplenodeapp --delete_oldest --force --image simplenodeapp --app_version 0.2

Note that if you want to remove/unpublish your app from ARS, you can use the following command:

amplify acs remove simplenodeapp

Summary

In this blog post we saw how you can easily publish a Node.js app Docker image to Axway’s ARS.

Discover more how-tos of AMPLIFY Runtime Services (API Runtime Services).