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

Build and Run Node.js Microservices with Zero Code (Well, Sort Of)

DZone's Guide to

Build and Run Node.js Microservices with Zero Code (Well, Sort Of)

Get a look at this handy module that can help you quickly set up microservices with a minimal amount of code.

· Integration Zone ·
Free Resource

The new Gartner Critical Capabilities report explains how APIs and microservices enable digital leaders to deliver better B2B, open banking and mobile projects.

Today, I'm introducing the npm module `microservice-bootstrap.`

It started as a hobby side project and was basically a scaffolding app for building API endpoints on top of expressJS. I've since added a whole suite of command line tools and made it as simple as it gets. See below how easy it is to create a new service in a few minutes (well, depending on how fast your Internet connection is).

Prerequisite 

This goes without saying, but you need npm. If you don't have it, Google it.

Then you want to install the command line tool, simply type in your terminal window:

npm install -g microservice-bootstrap

Create a new Project

Now go ahead and create a microservices project, say, 'my-awesome-api'. All you need to do is find a good location for it (let's use /tmp as this is an example), then type in:

microservice-bootstrap create -t /tmp/my-awesome-api

Wait for it to finish, and voila! There you have it.

Add new Service Modules

Note how I mentioned 'microservices' project with a plural 'services'? Yep, you can add as many services as you like, and you can choose which ones to run, so the idea is one code base with infinite possibilities. DevOps will thank you for that.

To add a new module, simply go to your project root directory (/tmp/my-awesome-api), and type in:

microservice-bootstrap add-service service1


And yes, you can add multiple ones in one go as well:

microservice-bootstrap add-service service1,service2,...


This will add services with clean folder structure, and an example endpoint (GET /service-name), e.g. if you added 'user' module, it will enable GET /user endpoint. 

Running the Service(s)

Running is no sweat, again, no code, just CLI... 

microservice-bootstrap run -e local -s service1 -v -p 8080


And yeah, you would have guessed, it supports multiple modules, just type:

microservice-bootstrap run -e local -s service1,service2 -v -p 8080

See it in Action

Check this out — service1 endpoint, freshly added with zero code change:


And, with a built-in debug (well non-production only, of course), you can get extra debug info right there:


There you have it, happy servicing (and coding)!

By the way, it comes with Cluster built in — it will automatically scale up to the number of processors on the server.

P.S.

Of course, with each command, adding -h will show you the man page. Go explore!

Related Refcard:

The new Gartner Critical Capabilities for Full Lifecycle API Management report shows how CA Technologies helps digital leaders with their B2B, open banking, and mobile initiatives. Get your copy from CA Technologies.

Topics:
nodejs ,micro service ,json ,npm

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}