The Wayback Machine - https://web.archive.org/web/20250111084558/https://www.geeksforgeeks.org/how-to-create-and-run-node-js-project-in-vs-code-editor/
Open In App

How to Create and Run Node.js Project in VS Code Editor ?

Last Updated : 07 Jan, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Visual Studio Code (VS Code) is a popular code editor for web development, offering a robust set of features that enhance productivity. In this article, we’ll walk you through the steps to create and run a Node.js project using VS Code.

Prerequisites:

Steps to create and run Node.js project in VS code editor

Step 1: Create a New Project Directory

Create an empty folder and move it into that folder from your VS Code editor, use the following command.

mkdir demo
cd demo
code .

Step 2: Now create a file app.js file in your folder as shown below.

Step 3: Installing Module

Install the modules using the following command.

npm install express
npm install nodemon

Step 4: Modify Package.json file

Add these two commands which are important for running and dynamically running the code after changes made in your Node.js app respectively in package.json file.

"start": "node app.js",
"dev": "nodemon app.js"

Configuration of package.json File:

{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"dev": "nodemon app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.12"
}
}

Step 5: Project Structure

Following will be our project structure

Step 6: Write down the following code in app.js file

JavaScript
// Requiring module
const express = require('express');

// Creating express object
const app = express();

// Handling GET request
app.get('/', (req, res) => { 
    res.send('A simple Node App is '
        + 'running on this server') 
    res.end() 
}) 

// Port Number
const PORT = process.env.PORT ||5000;

// Server Setup
app.listen(PORT,console.log(
  `Server started on port ${PORT}`));

Step 7: Run the application using the following command

npm run dev

Output:

Step 8: Open On Browser

Now go to http://localhost:5000/ in your browser, you will see the following output: 


Become an expert in solving problems with DSA JavaScript—the course designed to teach you Data Structures and Algorithms using JavaScript. Over the next 90 days, dive deep into key DSA concepts, learn to optimize your code, and gain hands-on experience solving challenging problems. Whether you're a beginner or looking to refine your JavaScript skills, this course will provide the knowledge you need to succeed.
Take on the Three 90 Challenge today! Complete 90% of the course within 90 days, and you’ll earn a 90% refund. This challenge is your chance to stay motivated, improve your skills, and get rewarded for your progress. Don’t wait—start your journey to DSA mastery with JavaScript today!


Next Article

Similar Reads

three90RightbarBannerImg