Setting Up VS Code & REPL Terminal for Node.js Development
Your development environment is where you'll spend the majority of your time as a Node.js developer. Visual Studio Code (VS Code) is the most popular code editor for Node.js development — and for good reason. Combined with the Node.js REPL (Read-Eval-Print Loop), you have a powerful setup for building, testing, and debugging applications.
1. Why VS Code for Node.js?
- Free & Open Source: No licensing costs, active community.
- Excellent Node.js Integration: Built-in debugging, terminal, and Git support.
- Massive Extension Ecosystem: Thousands of extensions for every need.
- Cross-Platform: Works on Windows, macOS, and Linux.
- Lightweight: Fast startup and low memory usage.
- IntelliSense: Smart code completion for JavaScript/TypeScript.
2. Installing VS Code
| Platform | Method | Command/Download |
|---|---|---|
| Windows | Official Installer | Download from code.visualstudio.com |
| macOS | Official Installer / Homebrew | brew install --cask visual-studio-code |
| Linux (Ubuntu/Debian) | Debian Package | sudo dpkg -i code_*.deb or Download .deb |
| Linux (Snap) | Snap | sudo snap install --classic code |
3. Essential VS Code Extensions for Node.js
These extensions will dramatically improve your Node.js development experience:
| Extension | Description | Publisher |
|---|---|---|
| ESLint | JavaScript linting (find and fix problems) | Microsoft |
| Prettier | Code formatter (consistent code style) | Prettier |
| NPM IntelliSense | Auto-completes npm module imports | Christian Kohler |
| Node.js Modules | Auto-completion for Node.js core modules | LeetCode |
| REST Client | Test APIs directly from VS Code | Huachao Mao |
| GitLens | Git history, blame annotations, and more | GitKraken |
| Thunder Client | API testing (Postman alternative) | Ranga Vadhineni |
| DotENV | Syntax highlighting for .env files | mikestead |
| Better Comments | Color-coded comments (TODO, FIXME) | Aaron Bond |
| Error Lens | Inline error highlighting | Usernamehw |
How to Install Extensions
# From command line
code --install-extension ms-vscode.vscode-typescript-next
code --install-extension esbenp.prettier-vscode
code --install-extension dbaeumer.vscode-eslint
# Or search by name in VS Code's Extensions panel (Ctrl+Shift+X)
4. VS Code Settings for Node.js
Add these settings to your settings.json file for an optimized Node.js development experience:
{
// Format on save
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
// ESLint auto-fix on save
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
// Use Node.js for terminals
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
// Auto-import suggestions
"typescript.suggest.autoImports": true,
"javascript.suggest.autoImports": true,
// Show npm scripts in explorer
"npm.enableScriptExplorer": true,
// Auto-close tags (HTML/JSX)
"html.autoClosingTags": true,
"javascript.autoClosingTags": true,
"typescript.autoClosingTags": true
}
5. Debugging Node.js Applications in VS Code
VS Code has built-in debugging support for Node.js. You can debug with breakpoints, step through code, inspect variables, and view the call stack.
Method 1: Run & Debug (Auto-attach)
- Open your Node.js project in VS Code.
- Press
Ctrl+Shift+D(orCmd+Shift+Don macOS) to open the Debug panel. - Click the "Run and Debug" button and select "Node.js".
- VS Code will automatically attach to your Node.js process.
Method 2: Configure launch.json
Create a .vscode/launch.json file for more control:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/index.js",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env",
"args": ["--max-old-space-size=4096"]
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 9229,
"restart": true,
"skipFiles": ["/**"]
},
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal"
}
]
}
Debugging with Breakpoints
To set a breakpoint: Click in the gutter (left margin) next to a line number. A red dot will appear.
To start debugging: Press F5 or click the green play button.
To step through: Use F10 (Step Over), F11 (Step Into), or Shift+F11 (Step Out).
To inspect variables: Hover over any variable in the editor or view the VARIABLES panel.
6. Integrated Terminal in VS Code
The integrated terminal allows you to run npm commands, start your Node.js server, and execute scripts without leaving the editor.
- Open terminal:
Ctrl+`(orCmd+`on macOS) - Create a new terminal:
Ctrl+Shift+` - Split terminal:
Ctrl+Shift+5 - Run npm scripts: Click the "Run" icon that appears above npm scripts in package.json
7. The Node.js REPL (Read-Eval-Print Loop)
The REPL is an interactive shell where you can execute JavaScript code instantly. It's perfect for testing snippets, experimenting with Node.js APIs, and debugging on the fly.
Starting the REPL
# In your terminal
node
# You'll see:
# Welcome to Node.js v22.x.x.
# Type ".help" for more information.
# >
Basic REPL Usage
// Simple arithmetic
> 2 + 2
4
// Variables
> const greeting = 'Hello, Node.js!';
undefined
> greeting
'Hello, Node.js!'
// Functions
> const add = (a, b) => a + b;
undefined
> add(5, 3)
8
// Arrays & Objects
> const user = { name: 'John', age: 30 };
undefined
> user.name
'John'
REPL Features
| Feature | Description | Example |
|---|---|---|
| Autocomplete | Press Tab to autocomplete | cons → console |
| Editor Mode | Write multi-line code | .editor |
| Load File | Load and execute a file | .load app.js |
| Save Session | Save REPL session to file | .save session.txt |
| Help | Show available commands | .help |
| Exit | Exit REPL | .exit or Ctrl+C twice |
Using .editor Mode
Write multi-line functions easily in the REPL:
> .editor
// Entering editor mode (Ctrl+D to finish)
function calculateTotal(items) {
return items.reduce((sum, item) => sum + item.price, 0);
}
// Calculate total
const cart = [{ price: 10 }, { price: 20 }, { price: 30 }];
calculateTotal(cart);
// Output after Ctrl+D:
// 60
>
Loading Files in REPL
// Load and execute a JavaScript file
> .load app.js
// Output: [file content and execution results]
// Load a module
> const fs = require('fs');
undefined
> fs.readFileSync('.help') // Shows help content
Using REPL for Quick Testing
// Test a regular expression
> const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
undefined
> regex.test('user@example.com')
true
> regex.test('invalid-email')
false
// Test a Node.js API
> const path = require('path');
undefined
> path.join('/user', 'docs', 'file.txt')
'/user/docs/file.txt'
> path.extname('file.txt')
'.txt'
8. VS Code Extensions for REPL Enhancement
| Extension | Description |
|---|---|
| Code Runner | Run code snippets directly in VS Code |
| Quokka.js | Real-time code execution feedback |
| JavaScript REPL | Run JavaScript in VS Code's integrated terminal |
| Node.js REPL | Node.js REPL inside VS Code |
9. Common Issues & Solutions
Issue 1: "command not found: node" in VS Code terminal
Solution: VS Code uses your system's PATH. Restart VS Code after installing Node.js. If it persists:
- Windows: Add Node.js to your PATH in System Environment Variables.
- macOS/Linux: Check if Node.js is in your shell profile (
echo $PATH).
Issue 2: ESLint not working
Solution: Make sure ESLint is installed locally (npm install eslint --save-dev). Install the ESLint extension and run npx eslint --init to generate config.
Issue 3: Debugger not attaching
Solution: Start your Node.js application with the --inspect flag:
node --inspect app.js
# Or with a specific port
node --inspect=9229 app.js
Then use the "Attach to Process" configuration in launch.json.
10. Production-Ready Checklist
- ✅ Install VS Code — Latest version from code.visualstudio.com.
- ✅ Install essential extensions — ESLint, Prettier, GitLens, npm IntelliSense.
- ✅ Configure ESLint —
npx eslint --initand add rules. - ✅ Set up Prettier — Add
.prettierrcand format on save. - ✅ Configure launch.json — Set up debugging configurations.
- ✅ Add .vscode folder — Share settings with your team.
- ✅ Use integrated terminal — Run npm commands without leaving VS Code.
- ✅ Master the REPL — Use it for testing and exploration.
- ✅ Install Git — Version control is essential.
- ✅ Set up .gitignore — Exclude node_modules/, .env, and dist/.
- ✅ Use workspace settings — Project-specific settings in
.vscode/settings.json. - ✅ Enable auto-save — Reduces the risk of losing changes.
11. Quick Reference — VS Code Shortcuts for Node.js Developers
| Shortcut | Action |
|---|---|
Ctrl+` (Cmd+`) | Open Integrated Terminal |
Ctrl+Shift+D | Open Debug Panel |
F5 | Start Debugging |
Ctrl+Shift+X | Open Extensions Panel |
Ctrl+P | Quick Open (find files) |
Ctrl+Shift+P | Command Palette |
Ctrl+Space | Trigger IntelliSense |
F12 | Go to Definition |
Shift+F12 | Find All References |
Ctrl+Shift+F | Search Across Files |
Ready to master Node.js?
Build scalable, high-performance backend applications with Node.js. Learn from industry experts with hands-on projects.
.png)