Express.js is a minimal and flexible Node.js web application framework. Follow these steps to install and set up Express.js:
Ensure you have the latest Node.js installed. Download it from Node.js.
To check your Node.js & npm version:
node -v # Should show Node.js version (e.g., v18.x or higher)
npm -v # Should show npm version (e.g., 9.x or higher)
Open the terminal and type this command with your project name:
mkdir my-project && cd my-project
Then, open the project folder with VS Code:
code .
npm init -y
This creates a package.json
file.
npm install express
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Hello, World!");
});
app.listen(3000, () => {
console.log("Server is running on port 3000");
});
Modify the package.json
file in your project and update the scripts section:
"scripts": {
"dev": "node index.js",
"build": "node index.js"
},
To run the Node.js server, execute the following command:
npm run dev # Development Mode
npm run build # Production Mode
Open http://localhost:3000/
in a browser to see the output.
This project is licensed under the MIT License - see the LICENSE file for details.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.