Express.js is a fast, unopinionated web framework for Node.js.
Express.js is a fast, unopinionated web framework for Node.js. It provides a simple and flexible way to handle HTTP requests and responses, and it's widely used for building web applications and APIs.
Express.js is built on top of the Node.js runtime, which means it can be used with any Node.js-based server, such as the built-in `http` module or the `express-ws` module. It also provides a set of features that make it easy to build web applications, such as routing, middleware, and template engines.
Here's an example of a simple Express.js application:
```javascript
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello, World!");
res.end();
});
app.listen(3000, () => {
console.log("Server is running on port 3000");
});
```
In this example, we create an Express.js application using the `express` module. We define a route for the root URL ("/") using the `app.get()` method. When a GET request is made to the root URL, the callback function is executed, and it sends the string "Hello, World!" as the response.
We also call the `app.listen()` method to start the server and specify the port number (3000 in this case). This tells the server to listen for incoming requests on port 3000.
## Express.js Features
Here are some of the key features of Express.js:
- Routing: Express.js provides a powerful routing system that allows you to define routes for different URLs and handle them accordingly.