Setting up development environment (with VSCode)
A development environment is the set of tools you use to write, run and test code. For JavaScript, a simple and popular setup is Visual Studio Code (VS Code) as the editor, a modern browser with developer tools, and Node.js for running scripts outside the browser. Setting these up properly from the start saves you from fighting your tools later.
What to install
- VS Code, a free code editor available for Windows, macOS and Linux. During installation on Windows, tick the options to add "Open with Code" to the right-click menu and to add VS Code to the PATH.
- A current browser such as Chrome, Edge or Firefox. You will use its developer tools constantly.
- Node.js, choosing the LTS (long-term support) version. It also installs
npm, the package manager used to add tools and libraries.
Checking the installation and creating a project
Open a terminal, or VS Code's built-in terminal with Ctrl and the backtick key, and run:
node -v # prints the Node.js version, e.g. v20.x
npm -v # prints the npm version
mkdir js-practice
cd js-practice
code . # opens this folder in VS Code
# create a file and run it with Node
echo "console.log('Hello from Node');" > hello.js
node hello.js # Hello from Node
If node or code is "not recognised", close and reopen the terminal so it picks up the new PATH, or restart the computer.
Working in folders, not loose files
Always open a folder in VS Code (File, then Open Folder) rather than a single file. Many features, including search across files, the integrated terminal starting in the right place, and project settings, work properly only when VS Code knows the project root. Keep each project in its own folder with an index.html and a script.js or a src folder.
Extensions worth adding
| Extension | Why it helps |
|---|---|
| ESLint | Underlines likely bugs, such as unused variables or undefined names, as you type. |
| Prettier | Formats code consistently so you never align brackets by hand. |
| Live Server | Serves an HTML page on a local address and reloads the browser when you save. |
| Error Lens (optional) | Shows error messages directly on the line where they occur. |
Start small. Installing dozens of extensions at once slows the editor down and makes it harder to tell which one changes what.
Settings that make a difference
- Auto save: File menu, then Auto Save, so changes are written as you go.
- Format on save: enable
editor.formatOnSavein Settings and choose Prettier as the default formatter. - Tab size: set to 2 spaces, the common choice in JavaScript projects.
- Word wrap: turn on with Alt and Z when reading long lines.
A few shortcuts pay off on day one: Ctrl+P to open any file by name, Ctrl+Shift+P for the command palette, Ctrl+/ to comment a line, and Alt+Up or Alt+Down to move a line. On macOS, use Cmd instead of Ctrl.
A setup problem beginners hit
Opening an HTML file by double-clicking it loads it with a file:// address. Simple pages work, but fetch calls and JavaScript modules (<script type="module">) are blocked by the browser for security reasons, which produces confusing CORS errors. Use Live Server, or run a small local server, so the page loads from http://localhost. Another common issue is having two formatters fighting each other on save; pick one default formatter and disable the others for JavaScript.
Ready to code
With VS Code opened on a project folder, Node.js confirmed in the terminal, ESLint and Prettier configured, and Live Server serving your pages, you have a dependable base for every exercise that follows.
Ready to master real-world web development?
Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.