Por fabricio

Lost in Node.JS. Where to begin

Lost in Node.JS. Where to begin


Learn anything is always hard. To feel lost and don’t know where to begin.

To help you, who wants (and will) develop in Node.JS, we did this little step-by-step  with everything you need to know to find yourself in this runtime created by Ryan Dahl, in 2009, and one of the most used web technologies today.

One step behind

Before we start to talk about Node.JS, is important to know that is not a framework. It’s a runtime. A set of libraries written in JavaScript that allows the execution of the JavaScrip code at the server. A server-side technology


Have you looked at the image above? Take a look again….V8. It’s a JavaScipt’s engine created by Google, written in c++ and used in Chrome.

Every JavaScript’s code you create will be interpreted by V8.  Meaning that is really fast. Only 17% slower than an optimized c++ code.

We did a little explanation about what Node.JS really is and a brief immersion at the runtime guts. Now it’s time to talk what you are looking for*: How to begin with Node.JS

 *Hold on! We know that what really matter is to practice. After all is the best way to learn something. But you need to know how things work. This will give you more knowledge and will be easier to put in practice what you will learn. So, you must read the official documentation. Although is much more focus in API, still a good read to learn about the use of the debugger, for example.  Will be useful too to take a look at V8 and how Event Loop works. At least, the book “Hands-on Node.JS“, from Paulo Teixeira, is excellent and one of the few focused at the core of Node.JS


The Hitchhiker’s Guide to the JavaScript Galaxy

Well, here you are, young man hungry for knowledge .

You’re a freshman (this is not a bad thing) and lost. This guide will help you. We don’t want you lost in this giant galaxy.

We separated the guide in Suns.

Sun 1

Main quest

  • Install Node.JS and NPM, the package manager. At the official website you have everything you need to complete this task.

  • Complete all challenges at NodeSchool.

    Very simple and direct, the NodeSchool content will make you use the main Node’s modules.

    Sun 2

    Main quest

    Objective: Create your first web application with Express.

    For this one you will need:

  • Talk to village ancient to know what to use. He will indicate Express, the web-framework most used (hint: when you learn something new, always use what is most utilized. Because that means a lot of things. One of them is a vast amount of material);

  • Install Express and make the Hello World;

  • Done! A piece of cake. Take advantage of this and make some side quests!

     Side quest

    If you are still at JavaScript Leve 1:

  • Don’t have nerd’s references like this one but is much more depth and an excellent source of how to learn JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide

  • Start a war! Make some exercise at CodeWars about JavaScript

    If you already completed some quests with JavaScript:

  • Review closures

  • Look OPP at JavaScript

  • Look HabitRPG’s Server.Js and study ES2015.

    If that was your first “Hello World” your next mission will sound challenging. Complete all previous side quests.


    Sun 3

    Main quest

    Create an application with Express and MongoDB.

    Let’s do like this:

  • Follow Zell Liew’s tutorials: Part 1 and Part 2 (source code)

    Completing the tutorials you will have a strong base to create CRUDs with Express and MongoDB. But, like almost every tutorial, lack the better structure of the application. Want to know how to structure? Do this side quest.


    Side quest

  • Refactor the existent code creating a new controllers layer. Use for reference the hackathon starter’s code. Observe that in app.js are the requires for the controller that have the treatment for each application route.


  • See Express’s examples, starting with https://github.com/expressjs/express/blob/master/examples/route-middleware/index.js, that shows how to use de middlewares.https://github.com/expressjs/express/tree/master/examples/route-separation.

    Sun 4

    Main quest

    Recreate the RSS-Feed-Emitter

    It’s time to learn new practices and to do this we have Filipe’s tutorial. It’s a great one because goes beyond “make work” and give you the tools to make simple things like publishing at NPM and even more complex tasks like how to test your application.

    It’s a 19 steps (counting the bonus parts) tutorial. Follow all steps and, if you do know something, check the links that you can find in the tutorial. https://github.com/filipedeschamps/rss-feed-emitter/issues/119

    Side quest

  • Complete all tutorial’s bonus.

  • Practice how to test your application with this tutorial: https://semaphoreci.com/community/tutorials/getting-started-with-node-js-and-mocha

  • More about tests (we really like tests). Now it’s time to know more about Sinon to create mocks, spies, and stubs: https://www.codementor.io/nodejs/tutorial/unit-testing-nodejs-tdd-mocha-sinon

    Sun 5

    Main quest

    Publish your application with PM2

    It’s time to publish the application created on Sun 3. To publish we will use PM2. Just follow this steps and the process.json will be created. You will also learn a variety of commands that PM2 have.

    Side quest

  • Publish your application at Digital Ocean (ou one virtual machine that you have)

  • Take a look at Cluster Mode

    Wrapping up

    If you conclude every quest, side quest included, congratulations!! You now have a strong base to start your project with Node.JS. You may be noticed that most part, until here, we used Express.

    Like we said at the beginning, is good to start with it. When you use Node.JS you will use together some web framework.

    Don’t forget to take a look at Hands-On. It will go further at the Node’s core. Besides that, you can make different applications, like a chat with Socket.IO or desktop with Electron.

    You are going on an adventure…

    Autor do Post

  • Recentes