DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. Build and Run Node.js Microservices with Zero Code (Well, Sort Of)

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.

Bruce Beibei Li user avatar by
Bruce Beibei Li
·
Sep. 10, 16 · Tutorial
Like (8)
Save
Tweet
Share
7.34K Views

Join the DZone community and get the full member experience.

Join For Free

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:

Node.js

microservice Node.js Sort (Unix) Build (game engine)

Published at DZone with permission of Bruce Beibei Li. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Java Development Trends 2023
  • Core Machine Learning Metrics
  • The Importance of Delegation in Management Teams
  • Promises, Thenables, and Lazy-Evaluation: What, Why, How

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: