How to Create a Node.js Project in VS Code

Creating a Node.js project in VS Code is straightforward. You can scaffold your application, set up scripts, and debug right from your editor. This guide walks you through installing the necessary tools, initializing your project, and configuring VS Code for a smooth development workflow.
By the end, you’ll have a working Node.js app, custom scripts in your package.json
, and a launch profile for debugging—all within VS Code.
Prerequisites
Before you begin, make sure you have:
- Node.js installed on your machine
- Visual Studio Code (VS Code) installed
- Basic familiarity with the command line
Tip: If you need to update Node.js, see how to update Node.js on Windows.
Install Node.js and VS Code
- Visit the official Node.js website and download the LTS version.
- Run the installer and follow the prompts.
- Install VS Code from the official site.
After installation, open a terminal and verify:
node --version
npm --version
You should see version numbers for both commands.
Initialize the Project
- Open VS Code.
- Open a new terminal (`Ctrl + ``).
Navigate to your workspace folder:
cd path/to/your/projects
Create a new folder and enter it:
mkdir my-node-app && cd my-node-app
Initialize your project:
npm init -y
A package.json
file will appear with defaults. You can edit fields like name
, version
, and description
later.
Configure VS Code
To boost productivity, add these files to your project root:
.vscode/launch.json
– for debugging..vscode/tasks.json
– for running build or test tasks.
Sample launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug App",
"program": "${workspaceFolder}/index.js"
}
]
}
You can start debugging with F5
once this file is in place.
Add Your First Script
Open package.json
and add a start
script:
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
}
npm start
will run your app.npm run dev
(with nodemon installed) reloads on file changes.
Write a Simple App
Create index.js
in your project root:
const http = require('http');
const PORT = process.env.PORT || 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, Node.js in VS Code!');
});
server.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
Install Dependencies
If you need extra packages, use npm or Yarn:
npm install express dotenv
# or
npm install -g yarn && yarn init
Tip: You can also manage packages with Yarn; see how to install Yarn using npm.
Run and Test Your App
Start the server:
npm start
- Open your browser at
http://localhost:3000
. - You should see Hello, Node.js in VS Code!
Use the Debug panel in VS Code to step through code, inspect variables, and set breakpoints.
Next Steps and Best Practices
- Add a
.gitignore
file to excludenode_modules/
. - Use ESLint and Prettier for consistent code style.
- Write unit tests with Jest or Mocha.
- Containerize your app with Docker for consistent environments.
“The best way to learn is by doing—build small features, tweak configs, and explore VS Code extensions.”
Conclusion
You’ve set up a basic Node.js project in VS Code, initialized your package.json
, added scripts, and configured debugging. From here, you can add frameworks like Express or NestJS, integrate testing, and automate tasks with GitHub Actions.
Getting your environment right from the start saves time down the road. Now that you know the essentials, experiment with extensions, linters, and deployment options to refine your workflow. Happy coding!
Subscribe to my newsletter
Read articles from Mateen Kiani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
