- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is express.js and installing it in Node.js?
Why requires express.js?
Writing core node.js code to fetch request data and parsing it is complex enough. As we saw in previous posts, we wrote data and end event to get the simple request data.
Express makes the process simpler. It helps developers to focus more on writing business logic instead of node’s internal complexity.
Express.js does the heavy lifting of node’s internal workings. There are some other alternatives to express.js are also available e.g. Adonis.js, Sails.js etc.
Installing express.js
Why –save and not –save-dev for express?
Express is a major runtime required library so it’s a dependency and not just dev dependency . That’s why we install it without –save-dev
Once added, we can see it in package.json file −
{ "name": "dev", "version": "1.0.0", "description": "", "main": "App.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "nodemon App.js" }, "author": "", "license": "ISC", "devDependencies": { "nodemon": "^2.0.3" }, "dependencies": { "express": "^4.17.1" } }
Import express in app.js
const express = require('express');
starting express.js −
const app = express();
So express is a function. It starts its internal process with the execution of express()
We can use express const in http createServer directly −
const http = require('http'); const express = require('express'); const app = express(); const server = http.createServer(app); server.listen(3000);
Now, we can run app, but it won’t handle any request as we have not defined any routes for it. In the next articles we will see the middleware concepts of express.js
- Related Articles
- Why is isNaN(null) == false in JS?
- SVG morphing in React JS
- Device Detection and Responsive Design in React JS
- Adding Lottie animation in React JS
- SVG drawing in React JS frontend
- HTML5 / JS storage event handler
- SVG zoom-in and zoom-out in React JS
- Drag and Drop a File feature in React JS
- Difference between Google Script (.GS) and JavaScript (.js)
- Selecting database inside the JS in MongoDB?
- Creating a Particle Animation in React JS
- Creating a Customizable Modal in React JS
- Creating animated loading skeletons in React JS
- JS Geolocation but without prompting possible?
- Why do I need Babel JS?
