Tuesday, December 24, 2024
ExplainerProgrammingTech/Web

ExpressJS – Web framework for Node.js

Expressjs

, or simply Express, is a web application framework for Node.js, released as free and open-source software under the MIT License. Express is a minimal, flexible and rapid development of Node.js web application framework that provides a robust set of features to develop web and mobile applications. It is designed for building web applications and APIs. It has been called the de facto standard server framework for Node.js. It is relatively minimal with many features available as plugins. Express is the backend component of the MEAN stack, together with the MongoDB database software and AngularJS frontend framework.

Express – Fast, unopinionated, minimalist web framework for Node.js

Expressjs has been utilised by many companies including Fox Sports, Uber and IBM. Express currently has over 500 million downloads, according to npm-stat.com (as of the 4th of December 2018).

You may like also : How To Install Node.js on Ubuntu

 Following are some of the core features of Express framework −

  • Allows to set up middlewares to respond to HTTP Requests.
  • Defines a routing table which is used to perform different actions based on HTTP Method and URL.
  • Allows to dynamically render HTML Pages based on passing arguments to templates.

Key Point of Experss

  • Web Applications -Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
  • APIs – With a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy.
  • Performance – Express provides a thin layer of fundamental web application features, without obscuring Node.js features that you know and love.
  • Frameworks – Many popular frameworks are based on Express.

Installing

Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory.

$ mkdir myapp
$ cd myapp

Use the npm init command to create a package.json file for your application. For more information on how package.json works, see Specifics of npm’s package.json handling.

$ npm init

This command prompts you for a number of things, such as the name and version of your application. For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception:

entry point: (index.js)

Enter app.js, or whatever you want the name of the main file to be. If you want it to be index.js, hit RETURN to accept the suggested default file name.

Now install Express in the myapp directory and save it in the dependencies list. For example:

$ npm install express --save

To install Express temporarily and not add it to the dependencies list:

$ npm install express --no-save

 

Hello world example

First create a directory named myapp, change to it and run npm init. Then install express as a dependency, as per the installation guide.

In the myapp directory, create a file named app.js and copy in the code from the example given below.

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

Run the app with the following command:

$ node app.js

Then, load http://localhost:3000/ in a browser to see the output.


You may like also:


Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

7 thoughts on “ExpressJS – Web framework for Node.js

Leave a Reply

Your email address will not be published. Required fields are marked *