devcareers
Published in

devcareers

The Node.js Roadmap;

Take the leap into Node.js :-)

If you started programming the conventional way you probably started off with the road that led from HTML to CSS and finally to javascript, from either a leading website like w3schools or a less popular website like html Dog like myself, although if you are like me you probably also abounded JavaScript to look for more visually pleasing language to learn. In any case, like me, you have circled right back to what you initial abandoned so sit tight and enjoy the ride.

I will be talking about some of the more basic concepts in node.js(because I can only cover so much in one article) and because I so much enjoy practical learning there will be live codes you can try out on your own(make sure you do).

First things first, you will need to install node on your device and there are quite a number of ways to do so. The first way to do so and my personal favorite is using the command line. Now if you are not used to the command line or just plainly hate it worry not, you can straight up install it using a downloadable executable file for your convinience :).

Most new folks new to coding usually come in with the windows operating system, so I’ll from there and progress forward for the tech bros(mac) and tech enthusiasts(linux).

  1. The Windows approach => To install using the command line for windows you will first have to install chocolatey from the official site. It has directions set in place so you cannot get lost and the best part is there will be other times you may have — or just want — to use chocolatey to install packages like npm, yarn even python and pip on your device. To install node open your command line and type.

For any of the other packages mentioned above all you have do is do the same thing. Installation takes the format “choco install <pkg name>” for all installations using chocolatey

2. The Others => I am not referring to the god feared by the north in A Song of Ice and Fire, just in case you’re wondering — if you know you know. I grouped the installation for mac and linux under this, cause they are broadly the same. What you actually want to do first here is install “nvm.” It stands for Node Version Manager. This will make your life infinitely easier in the long run cause with this you can basically manage which version of what is install on your system per time. It is pretty straightforward to install really.

On mac use the brew package. First make sure homebrew is installed on your system

On linux you want to make use of the auto-install script available. This is done using either the curl or wget package(I’m sure you can do it with a python script as well but that’s just complicating things unnecessarily).

With nvm installed you can install any version of node you want per time. The best part is this covers your npm installations as well. Neat right

An alternative to the command line would be to download node from the official site and run it(you should also get chocolatey here but it just looks cooler on the terminal).

Now it is important to know what node.js is. It is neither a framework nor a library, it a platform for running JavaScript code outside your browser. It is similar in functionality to the python interpreter and if you did not already know, javascript is an interpreted language — and a weakly typed one, so consider learning typescript.

Now the final thing I would like to touch on in this article(because it’s kind of getting long and that would not be very nice for learning) is how to create a simple server.

Node comes with a number of built-in modules but all have to be imported(or required) for them to take root in your project.

Starting your node project, the first thing you want to do is to create a folder — anywhere on your system/laptop for the project. Next is to open up your terminal(if you created the folder manually) and navigate to the folder you created. If you do not already know how to do this, check out this video or any other video you can find on the subject. When you have navigated to the folder type “npm init --y” or if you want to be able to edit your package.json file yourself like me use “npm init” instead. Now if you don’t know what a packakge.json file is don’t worry too much about it, just enter type those in and you’ll be fine.

Wielding the Power of Node.js

Creating a server in Node is a simple thing and it is only the beginning. Open up your text editor and create a new JavaScript file in the folder directory you created earlier and write this simple code.

This is as simple a server as you can create without installing packages.

Just in case some of this code looks strange, you might want to check out ES6 arrow functions as well as the const keyword. And perhaps do a quick recap of javascript as a language just for good measure.

http is a builtin package that comes with node when you install it.

“const http” is a way to declare http as a variable and the require keyword is a way to import modules be it builtin or third party modules. The http within parenthesis in front of the require keyword is the module being import and declared as the variable. This is the general format for which importation works in a node project.

Congratulations you now wield some of the power of Node. Hungry for more? I will be going a little deeper in the next one so do come back.

Cheers!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store