DEV Community

Sampson Ovuoba for Devwares

Posted on • Originally published at devwares.com on

What is Nodejs, Express and When Should It Be Used.

What is Node.js

According to the Node.js docs, Node.js can be defined as an asynchronous event-driven JavaScript runtime built on Chrome's V8 JavaScript engine.

A Brief Node.js History

On December 5th 1995, JavaScript was invented, created as a client-side programming language. It was used almost entirely just for the frontend of the website alongside the famous duo HTML ( HyperText Markup Language ) and CSS ( Cascading Style Sheet ). Seeing as JavaScript is regarded as an 'actual programming language', it required an engine to translate this language to Machine Language that the machine would understand, and that's when the JavaScript Engine came to our rescue.

There are different browsers, and these browsers have other JavaScript engines. Some of these JavaScript engines are :

  • V8: This engine was created by Google. It is the most used JavaScript engine right now, and it is used by browsers like Google Chrome and Chromium-based browsers like Internet Explorer Edge.
  • SpiderMonkey: This engine was created by Mozilla and is used in the Firefox browser.
  • JavaScriptCore: Apple's engine for its Safari browser.

JavaScript is easy to use and has a large community of developers to quickly consult for help or guidance when you run into issues. Therefore, as a result, that became a popular programming language. People started thinking about making this language cross-platform, meaning on the mobile, on the server etc., and the intelligent people behind their computers came up with a solution.

The solution was to use V8 (Google's JavaScript Engine ) to create a runtime environment that will work on the machine. V8 was chosen, I think, as a result of how fast the JavaScript engine was in transforming code to machine language. This runtime built on top of V8 is known as Node.js. Node.js is a JavaScript engine that runs on a physical machine. Adding the HTTP module to this runtime allows us to use it on the server-side.

Features of Node.js

Node.js is well known for its being asynchronous, non-blocking and single-threaded. A single thread is used to handle a request when a request arrives. Usually, the request requires us to fetch some sort of data from the database, which might take a bit of time. As a result of Node.js being non-blocking, it does not need to wait for that request or operation to execute other code.

Where is Node.js used

  • Non-blocking Operations.
  • Event-driven Operations.
  • Data-Intensive Applications.
  • I/O Intensive Applications.

Non-blocking : This refers to operations that do not block other operations from executing even if the operation has not been completed.

Node.js is well known for its being asynchronous, non-blocking and single-threaded. A single thread is used to handle a request when a request arrives. Usually, the request requires us to fetch some sort of data from the database, which might take a bit of time. As a result of Node.js being non-blocking, it does not need to wait for that request or operation to continue executing other code. It just runs the callback when the operation is done.

Event-driven

As its name suggests, an event-driven code or application is run or 'driven' by events. In Node.js, when we start our server, Node initiates the variables, declare the function that we have written and waits for the events that we have written functions for to occur.

Data-Intensive

Data-Intensive applications fetch, send, and maybe save a lot of data.

I/O Intensive

I/O stands for input-output, and I/O intensive application is an application dependent on an external application, meaning that the application sometimes needs to wait for an external device before it can complete its operation.

What is Expressjs

We have just learned that Node.js is not a language nor a framework. It's a runtime environment, so what exactly is the framework that Node.js runs, and this is Expressjs.

Expressjs makes it easier to build secure and fast web applications, just more straightforward, in general, to get work done. It is lightweight and organises our web applications into a more organised MVC ( model view controller ) architecture. This gives us the space and mental energy to focus on business logic.

Expressjs is a popular tool in developer circles because :

  • Express.js is a JavaScript framework, JavaScript as we have discussed earlier, it is easy to understand, has a large community to reach out to.
  • Express.js makes writing backend code for web applications easier.
  • Express.js also gifts our application with flexible middleware, which executes during the lifecycle o a request to the Express server.

Create Stunning Websites and Web Apps

Trying to build out all user interfaces and components for your website or web app from scratch can become a very tedious task. A huge reason why we created Contrast Bootstrap to help reduce the amount of time we spend doing that, so we can focus on building some other aspects of the project. Contrast Bootstrap PRO consists of a UI Kit featuring over 10000+ component variants. Together with a template of 5 admin dashboards and 23+ additional multipurpose pages template for building almost any type of website or web app. You can view a demo and learn more about Contrast by clicking here.

Contrast

Contrast Bootstrap PRO was built using the most popular CSS
framework Bootstrap to help build your next landing, admin SAAS, prelaunch etc project with a clean, prebuilt and well documented template and UI components. Learn more about contrast.

Resources

You may find the following resources useful:

Top comments (0)