How to Run Node.js in Visual Studio Code on Windows 11

If you’ve just installed Node.js and Visual Studio Code (VS Code) on your Windows 11 PC and are wondering how to actually run your JavaScript code — you’re in the right place. Setting up Node.js to run inside VS Code only takes a few minutes, but it’s an essential step for web developers working with back-end or full-stack projects.

In this guide, we’ll walk you through how to run Node.js in Visual Studio Code, verify your setup, and fix common issues that can prevent Node from executing properly.

What You’ll Need

Before we get started, make sure you have the following installed:

  1. Node.js (LTS version recommended)
    • Download Node.js and install it with the default options.
    • Don’t forget to check the box that says “Add to PATH” during installation.
  2. Visual Studio Code

Once both are installed, you’re ready to go.

Step 1: Verify Node.js Installation

Before running Node in VS Code, let’s confirm that Node.js and npm are properly installed.

Open Command Prompt or PowerShell and run:

node -v
npm -v

If you see version numbers for both Node.js and npm (for example, v20.12.0 and 10.2.4), that means Node is correctly installed.

If not, reinstall Node.js and ensure it’s added to your system PATH.

Step 2: Open Your Project Folder in VS Code

Now, open VS Code and either:

  • Click File → Open Folder and select your Node.js project folder, or
  • Create a new folder for your project and open it in VS Code.

Once inside the editor, you can create a new JavaScript file (e.g., app.js) by right-clicking in the Explorer panel and selecting New File.

Step 3: Write a Simple Node.js Script

Let’s create a simple Node.js script to test everything.

In your app.js file, type the following code:

console.log("Hello from Node.js!");

This simple script will help confirm that VS Code can run Node.js properly.

Step 4: Run the Code in VS Code Terminal

To run your code inside VS Code:

  1. Click on Terminal → New Terminal from the top menu.
  2. Make sure your terminal’s path matches your project folder.
  3. Run the following command:
node app.js

You should see the output:

Hello from Node.js!

That means Node.js is successfully running inside Visual Studio Code.

Step 5: Create and Run a Simple Web Server (Optional)

To take things further, you can use Node.js to create a basic web server using the built-in http module.

In your app.js, replace the code with this:

const http = require('http');

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World from Node.js Server!');
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

Now run:

node app.js

You should see the message:

Server running at http://localhost:3000/

Open that link in your browser, and you’ll see your Node.js server in action.

Step 6: Fix Common Node.js Execution Problems

If Node.js isn’t running inside VS Code, here are some quick fixes:

1. ‘node’ is not recognized as an internal or external command

This means Node.js isn’t added to your PATH. Reinstall Node.js and ensure you check the “Add to PATH” option.
You can also manually add this path:

C:\Program Files\nodejs\

2. npm not found or permission errors

Run VS Code as Administrator and try again.
If the issue persists, reinstall Node.js and select Repair during installation.

3. Script not found or wrong directory

Make sure your terminal is open in the correct project folder. You can check with:

cd path\to\your\project

Step 7: (Optional) Install Node.js Extensions in VS Code

To make development smoother, install these useful extensions from the VS Code Marketplace:

  • Node.js Modules Intellisense – helps with auto-importing modules.
  • npm IntelliSense – autocomplete for npm packages.
  • Debugger for Node.js – allows you to debug your Node applications easily.

Conclusion

Running Node.js in Visual Studio Code is simple once you’ve got Node installed and added to your system PATH. With VS Code’s integrated terminal and debugging tools, it’s the perfect environment for developing and testing Node-based applications.

Now that your setup is ready, try building a simple REST API or experiment with frameworks like Express.js — you’ll be amazed how quickly you can get things running.

Posted by Arpita

With a background in Computer Science, she is passionate about sharing practical programming tips and tech know-how. From writing clean code to solving everyday tech problems, she breaks down complex topics into approachable guides that help others learn and grow.