Express is a fast, unopinionated and minimalist web framework for Node.js Express is a “server-side”or “back-end”framework. It is not comparable to client-side frameworks like React, Angular & Vue. It can be used in combination with those frameworks to build full stack applications.
- Makes building web applications with Node.js MUCH easier
- Used for both server rendered apps as well as API/Microservices
- Extremely light, fast and free
- Full Control of request and response
- By far the most popular Node framework
- Great to use with client side frameworks as it’s all JS
JS Fundamental (Objects, Array, Conditionals, etc) Basic Node.js & NPM, HTTP Status Codes, JSON and High Order Array Methods – forEach, map, filter Arrow Functions
const express = require(‘express’);
// Init express
const app = express();
// Create your endpoints/route handlers
app.get(‘/’, function(req. res) {
res.send(‘Hello World’);
});
// Listen on a port
app.listen(5000);
App.get(), app.post(), app.put(), app.delete(). Etc
Access to params, query strings, url parts, etc
Express has a router so we can store routes in separate files and export
We can parse incoming data with Body Parser
App.get(‘/’, function(req, res) {
// Fetch from database
// Load Pages
// Return JSON
// Full access to request & response
});
Middleware functions are functions that have access to the request and response object. Express has built in middleware but middleware also comes from 3rd party packages as well as custom middleware.
• Execute any codes
• Make changes to the request/response objects
• End response cycle
• Call next middleware in the stack
Install Postman, an API Development tool for testing purpose.
run npm install
node index