Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction:
2.
Getting started:
3.
FAQs
4.
Key Takeaways
Last Updated: Mar 27, 2024

Setting up Express.js

Introduction:

Previously, we have already covered what exactly node.js is and the reason for which we need them. We have also learned how it came into existence. In this article, hoping that you have already installed node.js, we will create a directory for holding the application and make that a working directory. Exciting, right!!? So without wasting any time, let’s get started. 


Happy So Excited GIF 

Source: Giphy

 

Getting started:

$ mkdir myapp
$ cd myapp

 

In the next step, we need to use the package.json package file for the application. If you need more information about the working of package.json, you can visit here.

$ npm init

 

This command gives rise to several things, like the name and version of the application. For the time being, we can use now RETURN to accept defaults for most of them, with the following exception:

entry point: (index.js)

 

Choose and enter the name of the main file. You can even name it app.js. But, if you need the previous name index.js, just click on return to backtrack to the default value.

In the following steps, we need to install the Express in the myapp directory and save it for the dependencies list.

$ npm install express --save

 

For installing Express temporarily, for the time being, we can also use:

$ npm install express --no-save

 

FAQs

  1. Mention the steps to execute Express.js in the terminal?
    The steps to execute Express.js in the terminal are:
    For checking if the node is already installed: node -v
    For checking if npm is already installed: npm -v
    We need to set up the project: mkdir express-tutorial && cd $_
    For getting started, change it to a folder.
     
  2. Can node JS die?
    No, the node JS can never die even if the type has stabilized a little over the years. As it’s working beyond 2021, it’s still the same and will keep working as it is.
     
  3. Why is Express JS preferred over Node js for server-side development?
    Express JS is also a node js framework with many more advantages and specifications that help run server-side applications much faster and smartly. Hence, it is more preferred.

Key Takeaways

In this article, we have how to set up and start working with Express JS. Further, we have covered some frequently asked questions, which generally come to mind when learning Express. 

Keeping the theoretical knowledge at our fingertips helps us get about half the work done. To gain complete understanding, practice is a must. To achieve thorough knowledge, visit our page.

Recommended Readings:

NPX vs NPM

Live masterclass