Use Express in your Node Application
Step 1: In the existing Node Application install Express.
npm install express
The updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18",
"react-dom": "^18",
"express": "^4.17.3",
},
Step 2: In the app.js file add the following code.
//app.js
const express = require('express');
const app = express();
const PORT = 4000;
// Define a basic route
app.get('/', (req, res) => {
res.send('Welcome To w3wiki!');
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Step 3: To start the application run the following command.
node app.js
Output:
What is Express?
Express.js, commonly referred to as Express, is a minimal and flexible web application framework for Node.js. It provides a robust set of features to develop web and mobile applications, making it a popular choice among developers for creating server-side applications. In this article, we’ll explore what Express is, its key features, and why it’s a preferred framework for many Node.js developers.
Contact Us