Credits to Pixabay

Node.js in 3 minutes

Aimee

--

We interact with JavaScript on a daily basis, unless you don’t use the internet, in which case I’m very curious how you came across this blog. If you go to any web page, chances are the pages you see and interact with are built by JavaScript or some framework based on the language. JavaScript operates on the client-side, which is a fancier way of saying it’s what the user sees.

Though the language has been around for maybe a decade, it’s easily the most popular language. Year after year, Stack Overflow’s survey lists JavaScript as its top language, followed closely by Python — the two are actually pretty much the most popular languages at the time of writing this. It’s no surprise then, that JavaScript developers are in high demand.

What is its purpose?

Really briefly, Node.JS was created by Ryan Dahl. It allows us to run JavaScript outside of the browser. It’s JavaScript, but on the server-side.

The reason I’m focusing on Node.js is because of the number of job postings I’ve seen in which knowledge of Node.js is highly preferred. I also wanted to read something concise about Node.js that nailed down the essentials: what is it, and how do I use it? At the end of the day, a major reason why I blog is to share what I learned. Tech is so vast and grows exponentially everyday, and that’s what makes it really exciting to be part of the industry.

Some quick things I learned: Node.js is an environment and not a framework. It does, however, allow for other JavaScript-based backend frameworks to run such as Express.js. For more examples, and another comprehensive guide and intro to Node.js, check out Sophia Martin’s blog here. Back to our point — Node.js is really fast, and because of the nature of JavaScript, it is single-threaded and asynchronous.

I began learning Node.js by deciding to build a full stack application using React and Express. Just kidding! I checked out blogs and watched some YouTube tutorials, and then implemented it.

This is the easiest way to begin your own Node.js server. After you create and name a new file in your terminal or IDE, begin by creating a new variable http, and require “http”. HTTP is built into the Node environment, and how we’ll indicate to our local machine we are working with the HTTP server.

Next, we are declaring a function, onResponse, which takes two parameters, request and response. What we call the function doesn’t matter as much as the parameters do. The function is going to write “Hello World!” in the event that a connection to our server is successful — hence the 200.

In order to see this, you will have to run

$node server.js

Once we run this function in our terminal, we can go to localhost:8000 and see our “Hello World” on the page.

Node.js is a great skill to add on to your stack, especially since JavaScript isn’t going anywhere anytime soon (I think). In addition, it’s easy to pick up for those who have experience with JavaScript on the client-side, and because it’s so popular, its documentation and packages are routinely updated and upgraded. Of course, it’s not perfect for every situation. There are a few drawbacks to Node. Overall, I encourage you to check out Node.js and build a simple app to get more experience, if you haven’t already.

--

--