Why we love Node.js

syd
3 min readAug 28, 2021

--

The first thing out of every new grad’s mouth is ‘OMG! I need to start learning this language, make a new application, learn every data structure and algo in the book…’ and the list goes on. So yes, you guessed right after graduating from Flatiron’s software engineering program, I decided to take on Node.js!

Let’s start at the beginning …. before Node.js came along, JavaScript was really only recognized as a frontend programming language but in 2009, Node came along and changed the game. Node.js allows developers to use JavaScript as a server-side language aka backend. What this means is that Node.js is not really a programming language but a runtime environment of a programming language. Say what?????! Node.js is a server-side software that contains predefined processes to accomplish specific tasks and uses JavaScript to conduct these backend processes.

The main reason why Node.js is so damn special is because a developer can still create a whole frontend and backend application with just using JavaScript essentially. Before Node.js, JavaScript was only used as a client-side language so when a user submitted a form or clicked a button, another language would take over for the backend to store that information from the form or take the user to that specified link from the button. But Node.js and JavaScript are the dynamic duo that changed all this! And big companies like Netflix and Uber have hopped on the trend and swear by the beloved Node.js!

Now how exactly does this JavaScript runtime environment work you ask? Node.js runs on V8 engine (which is used to compile and execute JS source code), so when you execute a JS script using Node.js, that code is initially passed to the V8 JavaScript engine. A big part of why Node.js is gaining popularity is because it is asynchronous and event-driven. In other systems, there is usually a blocking call to start the event-loop but not Node.js! Node.js simply enters the event loop after executing the input script and then exits the event loops when there are no more callbacks to perform. Basically, Node.js makes developers’ lives so much easier and less code to write! I mean win- win right?!

Let’s now create our first Node.js Script! As you might have thought Node.js has a little something to do with the node module system and one of the most popular Node.js modules is the file system module where it allows a developer to communicate with files on any machine.

First thing is first, we need to import the module. The Node.js file system module is cleverly represented by the fs, so by requiring and naming a variable (which could be named anything but in the above example is ‘const fs’), you now have access to the file system module. This file system module is god’s gift to Node.js! But in the above example we are simply using the writeFile. The writeFile function takes three arguments: a filename, the data that you want stored in the file, and of course a callback function. Our callback function takes an error argument as well (if for some sad reason a problem may arise). Now to execute this Node.js script, just simply open a terminal and run ‘node filename.js’ and that’s it folks! Simply and easy enough!

Since we have a little intro to executing a Node.js script — below is a lil snippet of how beautiful and easy it is to implement Node.js as your server-side language…

I hope this clears up some questions and give you the courage to tackle this runtime environment! Node.js has made it so JavaScript developers can be recognized as backend and even full stack developers which changes the industry so much!

Connect with me on linkedin and let’s be friends, Happy coding fam!

--

--

syd

software engineer. red wine addict. obsessed with vintage cars and jewelry.