Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Build microservices in Node.js with micro

    Max StoiberMax Stoiber

    micro is a small module that makes it easy to write high performance and asynchronous microservices in Node.js. This video will introduce you to micro by building a tiny service that responds to all requests.

    nodeNode.js
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:01 First, we npm-install the micro module with the -g global flag. This will give us access to the micro command, which we'll use later on to start our micro service. Then we create an index.js file, which we will write our first micro service into.

    00:16 In this file, we require the send function from micro. This is the main function we'll use when writing your micro services. It allows you to send responses back to the client. To write our micro service, all we have to do is export the function, which gets two arguments, the request that comes in and the response object, which we can send back to the client.

    00:40 Let's do that. We use the send function to send the response object with an http status code of 200, which means a successful request, and a body. In our case, we'll say, "Hello, world." We'll save this and start our first micro service by typing micro index.js.

    00:59 This starts our micro service. As you can see, we can access it at 0000and then port 3000. If you open this in your browser, you will see that our micro service responds with our "Hello, World" message.

    Discuss

    Discuss