How to Create and Run a Node.js Project in VS Code Editor ?
Last Updated :
10 Apr, 2025
Visual Studio Code (VS Code) is a powerful and user-friendly code editor that is widely used for web development. It comes with features like syntax highlighting, code suggestions, and extensions that make coding easier. In this article, we'll show you how to quickly create and run a Node.js project using VS Code.
Prerequisites:
Steps to create and run a 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
- express is the web framework for Node.js.
- nodemon is an optional tool that automatically restarts your application when code changes (useful for development).
Step 4: Modify Package.json file
1. Open the package.json file (it should be automatically created after running npm init or installing any modules).
2. Add the following commands under the scripts section to run the application:
"scripts": {
"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": "^5.1.0",
"nodemon": "^3.1.9"
}
}
Step 5: Project Structure
The following is the 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
Go back to your terminal and run the following command to start the server with nodemon:
npm run dev
- npm run dev will run the server and automatically restart it when you make changes.
Output:

Step 8: Open On Browser
Now go to http://localhost:5000/ in your browser, you will see the following output:

Similar Reads
How to use External Modules and NPM in a project ? Need for External Modules: For a large JavaScript application, it becomes difficult and messy to write the whole code in just one JavaScript file. This is where CommonJS comes into the picture and this CommonJS format defines a module format that can be used up for breaking your JS application into
3 min read
How to Install Node & Run NPM in VS Code? Node.js is an open-source, server-side JavaScript runtime environment built on the V8 engine. It allows developers to execute JavaScript code outside of a web browser. In this article, we will see how to install Node.js and NPM and install packages in VS Code using NPM. Steps to Install NodeJS and N
2 min read
How to Install Express in a Node Project? ExpressJS is a popular, lightweight web framework for NodeJS that simplifies the process of building web applications and APIs. It provides a robust set of features for creating server-side applications, including routing, middleware support, and easy integration with databases and other services.Be
2 min read
How to Run Node.js Program as an Executable ? Node.js allows you to create standalone executables from your JavaScript programs, making them easy to distribute and run on various platforms without requiring Node.js to be installed. This article will guide you through the process of converting a Node.js program into an executable file using popu
2 min read
Folder structure for a Node JS project Organizing a Node JS project with well planned folder structure is crucial for readability, scalability, and maintainability. A clear structure helps in managing code, configurations, modules, and other assets effectively. In this article, we are going to learn the folder structure of the Node JS pr
5 min read