Skip to main content

A comparison between Node and Express

If you are programmer who have worked a long time with JavaScript you might know that , earlier JavaScript was just a scripting language used in the client side. However now the story is different. With many libraries like Node js and Express js being added to the JavaScript family JavaScript have evolved beyond, just being a scripting language in the client side. With these new libraries being added, now it is possible to build entire sites on JavaScript, extending it from front to back-end seamlessly. So what is Node and Express? Let's  clear this out step by step!

What is Node js?

Node js is an open source JavaScript runtime environment that executes JavaScript code server side. Node enables developers to use JavaScript for server side scripting. Node uses an event driven, non-blocking I/O model that makes it light weight and efficient. Because of this model Node js is particularly useful in web application that have many input/output operations and for real time web applications. Node is built on V8 engine , which is Chrome's JavaScript engine. 

A key feature of Node is it's event loop. Whenever Node comes across a time consuming I/O operation, it registers this in the event loop and let it handle the operation. During the time event loop handles the I/O operation, the main thread can continue executing its other tasks. Once the event loop finish executing the task , it notifies this to the main thread using a callback. Having an event loop Node serves well for applications  with heavy input/output operations, but not that efficient for applications with heavy computational tasks.

What is Express js?

Express is a web application framework for Node js. Like Node, Express is also open source and cross platform. Express is light weight and helps you to organize your web application into an MVC architecture on the server side.

Comparison

Node is a platform for building server side event-driven I/O applications using JavaScript, Express is a framework based on node js and makes it easier to work with node. To make it more clear , we can say that Node is like a programming language such as Java, C , C++,  etc., and Express is like a header file added to it.

Downloading and installing Node

1.Download: Download Node.js's package ecosystem, npm (node package manager). npm download
2.Run: Run the installer wizard.
3.Restart : Once installed, restart your PC to work with node.
4.Check: To check whether Node is successfully installed, open a command prompt and type 'node -v' . This will give you the node version installed to your PC.
5.Initialize: To initialize a node.js project directory, first make a folder in a preferred location. Open a command prompt inside your folder and type 'npm init' command. This will create a package.json file inside your folder. package.json is like a manifest file and contains a list of all the packages that our project depends on. An example is provided below.


6.Add Express: Add ExpressJS module to your project using the following command 'npm install express --save'. 


After installing express module your package.json will look like this:





Comments

Popular posts from this blog

How to get started with MongoDB

In my last post I gave you all a brief introduction about NoSQL databases and its uses. As I mentioned in my last post , in this blogpost I'll give you all an overview of MongoDB and how to get started using MongoDB. Basically MongoDB is a document-oriented, NoSQL database and it can be rated as the most popular and widely used NoSQL database. MongoDB is free and open source , therefore anyone can simply download it from their site and start using it in their applications. It stores data as JSON(JavaScript Object Notation) like documents with schemas. In fact, data is actually stored in MongoDB as BSON objects. BSON is very much similar to JSON except that it is the binary representation of JSON. Unlike JSON, BSON is optimized for performance and navigational abilities. Typically data will be stored in the format shown on the following picture.  Key features that had contributed to the huge popularity of MongoDB are as follows: Support Ad hoc queries together JavaScript ...

Difference between callback functions and promises in javascript

If you have ever worked with JavaScript you might have the experience that it is a quite confusing language to understand at first. This is because  in JavaScript there are many ways to do the same thing, and also unlike most other programming languages, if you do a small mistake in JavaScript instead of giving any errors, the program would behave in a totally different way than what you expect. Therefore, without understanding the basic concepts of JavaScript, it's quite difficult to work with it. In this post I'll be explaining about callback functions and promises, what they are used for and the difference between the two methods. Actually callback functions and promises are 2 different ways of doing the same thing. By default JavaScript is an asynchronous programming language. Which means that JavaScript does not execute instructions line after the other as in many programming languages. Whenever JavaScript come across an operation that takes relatively a long time, typic...