Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Deploying APIs Built Via Node.js to IBM Bluemix

DZone's Guide to

Deploying APIs Built Via Node.js to IBM Bluemix

Learn how to deploy Node.js applications to IBM Bluemix as Docker containers.

· Cloud Zone
Free Resource

MongoDB Atlas is a database as a service that makes it easy to deploy, manage, and scale MongoDB. So you can focus on innovation, not operations. Brought to you in partnership with MongoDB.

In my previous article I described how to use Swagger to document APIs in Node.js applications via a simple hello world sample. Below I demonstrate how to deploy the same sample to Bluemix via Docker and how to use the API Management service to enforce client ids and secrets when invoking the APIs so that API owners can monitor the usage of their APIs.

Deploying Node.js Applications to IBM Bluemix as Docker Containers

First you need to add a Dockerfile to your project’s root directory. The documentation describes how to do this. Since I don’t need SSH I use a simpler Dockerfile.

FROM registry.ng.bluemix.net/ibmnode:latest
COPY . /node
WORKDIR /node
RUN npm install
EXPOSE 9080
CMD ["node", "/node/app.js"]

Since the IBM Containers (Docker hosted on Bluemix) only support specific ports I use the port 9080 instead of 10010 as in the original sample. I also had to change the port in app.js and swagger.yaml. In order to run the application locally you need to invoke the following URLs.

http://127.0.0.1:9080/hello?name=Niklas
http://127.0.0.1:9080/swagger

To build the Docker image and to run it locally invoke the following commands from the root directory.

docker build -t node-swagger-hello-world .
docker run --name node-swagger-hello-world -p 80:9080 -d -t node-swagger-hello-world

After this you can run the sample in our local Docker environment.

http://dockerhost/hello?name=Niklas
http://dockerhost/swagger

In order to push the image to Bluemix invoke the following commands.

To run the sample on Bluemix create a Docker container group.

swaggerdockernode

After this you can run your REST API on Bluemix.

http://node-swagger-docker-hello-world.mybluemix.net/swagger
http://node-swagger-docker-hello-world.mybluemix.net/hello?name=Niklas

Usage of the API Management Service

With the API Management service in Bluemix you can manage and monitor your APIs. In the next part I describe how to enforce a client id and secret when invoking the API so that you can track which applications called which APIs. The API definition can be imported via pointing to the Swagger 2.0 definition above and additional settings can be configured in the dashboard of the API Management service.

swaggerdockernodeapi

In order to invoke APIs applications developers need to register applications.

swaggerdockernodeapp

Applications can subscribe to plans with the APIs they are interested in and test the APIs directly from the developer portals by providing the client ids and secrets.

MongoDB Atlas is the best way to run MongoDB on AWS — highly secure by default, highly available, and fully elastic. Get started free. Brought to you in partnership with MongoDB.

Topics:
ibm bluemix ,node js

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}