In this tutorial, you will learn how to build and setup node js project with express js framework.
Here are steps:
Step 1: Install Node Js
To install and set up Express Project, you need to install Node JS in your system. If you don’t know how to install and setup Node JS, you can read these guides according to your OS system:
- How to Install Node.js and NPM on Windows 11
- How to Install Node js and npm on Ubuntu
- How to Install Node JS on CentOS
Step 2: Create A New Project
Type the mkdir ExpressApp
command on CMD or terminal window to create a new project directory for your Express JS application:
mkdir ExpressApp
To navigate to your expressApp directory by using cd ExpressApp
command:
cd ExpressApp
Step 3: Install Express JS
Simply type npm init -y
command on cmd or terminal and hit enter to set up node js and npm related packages in your express node js application or project:
npm init -y
To install Express JS, just type npm install express -save
command and hit enter to install express js into your project directory:
npm install express -save
Step 4: Setup Express js App
To create the main entry point into your express node js app, simply use touch index.js
or type nul > index.js
on cmd or terminal window to create file:
For ubuntu and mac os::
touch index.js
For Windows:
type nul > index.js
After that, add the following lines of code to the app.js file:
const express = require('express'); const app = express(); const port = 3000; app.get('/', (req, res) => res.send('Hello World!')); app.listen(port, () => console.log(`Express app running on port ${port}!`));
Step 5: Test Node Express js Application
Run npm start
command on cmd or terminal window to start node express js application:
node index.js or npm start
Open browser and hit http://localhost:3000
to test your first Express Node JS application.
Conclusion
Congratulations! You have successfully created and set up your first create node js project with express js.