Express.js is a popular and widely-used web application framework for Node.js, simplifying the process of creating web applications and APIs. Installed in 2016, the latest version of Express.js is 1.0.0, and it’s used in over 7 other projects in the npm registry. To get started, simply run npm install express.js in your terminal.
Express.js offers a robust set of features for handling routing, middleware, and template engines, making it a popular choice for developers due to its minimalist design, flexibility, and ease of use.
Here’s a simple example of how to create a web server using Express.js:
- Install Express.js using
npm install express.js - Create a new file called
app.jsand add the following code:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000, () => {
console.log('Example app listening on port 3000!');
});
- Start the server by running
node app.jsin your terminal. - Open your web browser and navigate to
http://localhost:3000. You should see the message “Hello World!”.
For more information and advanced features, refer to the Express.js documentation.