Express.js is a web application framework for Node.js, designed for building web applications and APIs. It provides a set of features that make web application development simpler, including routing, request handling, and session management.
Example:
Let’s say you want to create a web application that allows users to post comments on a blog post. With Express.js, you can create a route that allows users to submit comments. The route might look something like this:
app.post(‘/blog/:postId/comments’, (req, res) => {
const postId = req.params.postId;
const comment = req.body.comment;
// Save comment to database
// …
res.status(201).json({
message: ‘Comment successfully saved!’
});
});