Set up VS Code and Node
You'll learn to install VS Code and Node.js, open a project folder, and run your first JavaScript file.
Watch & read
Start with the required ones. The others are there when you need them.
Explanation
You need two tools before you write any code. A place to write it, and something that can run it.
VS Code is a free code editor. It is like a notebook made for code: it colours the words, shows your folders on the left, and has a terminal built in. Node.js is a program that runs JavaScript files on your computer, outside the browser.
Install both:
- VS Code from
code.visualstudio.com. - Node.js from
nodejs.org. Pick the LTS version. LTS means "long-term support": the stable one.
Now make a folder for your work, like projects/hello, with lowercase and no spaces. In VS Code, use
File, Open Folder and pick it. Always open the folder, not a single file. Then open the built-in
terminal with View, Terminal. It starts inside your folder already.
Check Node is installed, then make and run a tiny file:
node --versionv22.11.0
// hello.jsconst name = "Nusrat";console.log("Hello, " + name);
Save it, then type node hello.js in the terminal. You should see Hello, Nusrat. Your version number
may be different. Any recent LTS number is fine.
People often run node hello.js from the wrong folder, or forget to save first. Then Node says
Cannot find module or runs the old code. Check the terminal's folder with pwd, and look for the white
dot on the file's tab: it means "not saved yet".
Keep extensions to a minimum. Prettier tidies your code's spacing when you save. ESLint points out some mistakes, and you can add it later. You do not need anything else for now.
When you look at VS Code, find three things: the folder tree on the left, the open file in the middle,
and the terminal at the bottom. If the terminal's folder and the file's folder match, node will find it.
Code tour
Click a line number with a ring to read the note for that line.
Quick check
3 questions. Each one explains itself after you answer.
- 1 / 3Which Node.js version should you install?
- 2 / 3You run
node hello.jsand seeCannot find module. What should you check first? - 3 / 3Why open a whole folder in VS Code, not just one file?
Explain it back
How confident are you with Set up VS Code and Node?
Done
.js file with node.