Skip to content

omidnavy/nodejs-microservice-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

react boilerplate banner


Start your next node.js micro-service in seconds
A highly scalable and simple node.js boilerplate based on ES6 classes (without any transpiler) and GRPC

Created and maintained with ❤️by Omid Navy

Features

Straight forward
Build your next nodejs microservice in seconds
GRPC based
nodejs microservice boilerplate is based on GRPC, A high performance, open-source universal RPC framework.
ES6 Classes
Develope your node.js microservice using the power of ES6 classes without the need of transpilers! So develop and debug your code without headaches
MVC pattern
Build you micro-service in a well-known MVC architecture.

Keywords: Node.js, GRPC, Micro Service, ES6

Quick start

  1. Make sure that you have Node v8 or above installed.
  2. Clone this repo using git clone https://github.com/omidnavy/nodejs-microservice-boilerplate.git
  3. Move to the appropriate directory: cd nodejs-microservice-boilerplate.
  4. Run npm install in order to install dependencies .
  5. Run npm start to run sample.

Now you're ready to rumble!

Please note that this boilerplate is production-ready!

Documentation

  1. First, let's make a Protocol Buffer name it RouteMapper.proto and put it inside /app/core/.

  2. Open /app/core/RouteMapperMapper.js and edit packageName and serviceName variable depends on you .proto file.

  3. For every rpc function defined in your proto, you must have a component.

    • Create a folder inside app/components same as your rpc function name. eg. SayHello
    • Now make a [x]Controller.js inside this folder where x is your component name. use /app/components/SayHello/SayHelloController.js as your template.
    • You can declare model classes inside your component folder then require it in your controller class. Use /app/components/SayHello/myModel.js as your template.
    • There is a BaseController and BaseModel class inside /app/core/ which can have your common things for controllers and models.
  4. Time to run your app:

    npm run start

Database Class

There is a simple BaseDBModel in /app/core/ which is using mysql pooled connections wrapped in a promised based function. You can check the commented sample code for using it. You can modify it to use with other databases or remove it completely from your app if you don't need databases . don't forget to clean the code and uninstall mysql client using following command if you decide to remove or change database.

npm uninstall -s mysql

Helpers

Helpers are shared functions that can be called from anywhere in your app. here we use global variables to define our helper functions. There is logger helper function defined as sample , you can call it with logger() where ever you want. there is a child process for calling logger function to reduce cpu load on main app (don't take it serious , its just a showcase).

Process

If you want to use child process, you can use /app/core/child-process/winston.js as your template.

About

A highly scalable and simple NodeJS ES6 microservice boilerplate using GRPC

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published