why should i learn this?
if you’re favourite programming language is JavaScript chance are that you will be using Node.js as the backend for your next web-application. Node is awesome it gives you the power to write fullstack apps with a single codebase, launching you from beginner to fullstack developer in no time. But with great power …
As we all know developers often use tools as a blackbox. In principle nothing wrong with that of course, if the wheel is already there why reinvent it? Well I think there are cases where it can be usefull to delve a bit deeper.
problem: when starting out on my webdevelopment journey the focus was to build a fullstack application fast as possible in this process i used a lot of pre-made templates and a frameworks, an example of this is Express. This got me up to speed quickly and enabled me to set up a backend in no time. But i didn’t really know the basic concepts of what I was using.
In the case of node.js it is such a fundamental part of your stack that I think any developer can benefit from trying to understand the underlying concepts. As it will help you understand packages you use in your node.js backend.
introducing …. learnyounode

I won’t make this a 20 page tutorial on all the exercises, but i wanted to share with you guys what some of my key takeways were from completing these challenges. The best thing you could do is go solve them yourself when done reading this awesome article!
here is how to get started:
- npm install -g learnyounode
- type in learnyounode in your cmd prompt (if on windows) / (terminal if on mac)
if on windows don’t use other terminals like bash because they are not really compatible with the packag instead use the build in cmd prompt
and voila start to have some fun with Node.js. I embeded the solutions down below so if you get stuck along the way or have some improvements for my code feel free to leave a comment.
Take-aways
1: arguments from the command line
Let’s take some babysteps first, when launching a program in node we can pass arguments to that program via the command line 😎. these are then accessible via process.argv. This can be used to pass aflag to a script, an example of this most of us know would be npm install -g. Which executes your script in a different way compared to when you don’t use the flag.

2: Node Buffer Objects
Buffer objects are nodes way of representing data arrays. Data gets stored in instances of buffers which enables you to do some filesystem operations. Let’s say we want to access a file from or computer we can use the build in filesystem module and then do some magic on our buffer object its methods return converting a text document to a string for example. Careful though asynchronousity is a big part of filesystem operations.
3: Node Stream Objects
requests and responses are great but can you tell me what they actually are? When using express accessing the body of a request is as easy req.body or finding out the params as easy as req.params but what happens behind the scenes?
A stream is an abstract interface for working with streaming data in Node.js.
req and res are stream objects in node.js which are readable and writable aka. duplex streams meaning we can get data from it and attach data to it. Next to this these objects emit events, the three main ones being:
on('end',()=>{})
will only be emitted when all the data has been received. Because we receive the data async this will come in handy when we want to perform something only when all data is there.
on('data',(chunk)=>{})
as you can see we get a data event whenever data is received. it takes a callback giving you that data. in the exercise you will see this is data returned thanks to calling the http.get() method. carefull this will return you what we saw earlier the buffer object (we talk about data). So apply the relevant encoding.
on('error',(error)=>{})(needs no introduction)
4: Reading and writing upon connection
Ok now that we warmed up, let’s go a bit further. You probably already heard about the concept of websockets. Websockets can be used to listen to events emitted by connected users and then execute some logic if these events are emitted for example a chat where a user emits a new message event which will then broadcast that message to other connected users. sockets are also duplex streams meaning we can write and read on the object.
This is not the same as setting up a HTTP connection because we don’t have access to req and res objects. So let’s set up a HTTP connection. These last exercices give some great insight on how we can actualy use our req and res objects. In the exercices you will see that without a package like Express you need to modify some things yourself to send a back a JSON based upon url parameters. Below you can see an example on the difference between using express and using built in modules. You can see not using express gives you some extra work such a having to stringify your JSON response writing response headers and writing to the response object.