Micro

Let's look at another interesting tool. This module is called micro and was created by ZEIT, a team of some of the most influential Node.js developers. It is meant to be a minimalistic framework to create slim and fast microservices.

Let's repeat our first example. Create a folder and run the following command:

npm init -y
npm install --save micro

Now, create a file called app.js and write the following code inside it:

module.exports = (req, res) => {
res.end("Hello World");
};

Change your scripts property in package.json to this:

"scripts": {
"start": "micro"
},

Now, just run this:

npm start

You'll see something like this, which indicates that a micro is running on its default port, 3000:

micro: Accepting connections on port 3000

You can now refresh your browser and you will get the same page you saw earlier. But now, you have it with only three lines of code (and some configuration).

That's it. Micro is very minimalistic. You'll have to declare and install all your dependencies as it won't do anything other than enable you to write very slim microservices. This is handy if you don't want to carry the 2.3 MB of dependencies from our first Express example.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset