Setup: browser console & Node.js
10 min lesson
- Setting up means getting a place where you can type JavaScript and see the result, without installing anything complicated at first.
- You need this because you cannot write JavaScript in a plain text document and expect it to run; something must read and execute it.
- Think of it like a kitchen: the browser console is a small practice stove, and Node.js is a full kitchen you can use later.
- The browser console is a panel built into every browser where you can type one line of JavaScript and press Enter to run it immediately.
- Node.js is a free program that runs JavaScript outside the browser, on your computer, using a terminal window.
- A terminal is a text window where you type commands instead of clicking buttons.
- The basic form of using the browser console is: open DevTools (usually F12), click the Console tab, type 2 + 3 and press Enter.
- A realistic use is quickly testing a small idea before writing a whole file.
- An easy-to-miss detail: the browser console is temporary. If you refresh the page, anything you typed disappears.
- After this lesson you should be able to open the browser console, run a simple expression, and know that Node.js exists for running scripts on your computer.
- The browser console is the fastest way to try JavaScript right now.
- Node.js lets you run JavaScript files from a terminal on your computer.
- The console forgets everything when you refresh, so save real work in a file.
- Take your time with setup. Once it works, it works forever.
Breaking it down
Opening DevTools
Press F12 (or right-click, then Inspect)This opens the developer tools panel in your browser. It is where the console lives. Without it you cannot type JavaScript directly.
Console tab
Click 'Console'The console is the part of DevTools that runs JavaScript and shows messages. It is the quickest place to experiment.
Running a line
2 + 3 then EnterThe console runs the expression immediately and shows 5 below it. This proves JavaScript is working before you write files.
Node.js
node hello.jsIn a terminal, this command tells Node.js to run the file hello.js. Node.js reads the file and executes each line, like the browser does for scripts on a page.
Browser console vs Node.js
| Feature | Browser console | Node.js |
|---|---|---|
| Where it runs | Inside the browser | In a terminal on your computer |
| Best for | Quick one-line tests | Running saved script files |
| Keeps code after refresh | No, it disappears | Yes, the file stays on disk |
| Setup effort | None, it is built in | Download and install once |
A helpful analogy
Setting up is like choosing where to practise cooking. The browser console is a small hotplate in your kitchen: quick to use for one pancake. Node.js is the full oven and stove: more setup, but you can cook a whole meal. Start with the hotplate and move to the oven when you need it.
Nesting rules
- 1.If the console does not appear, make sure you clicked the Console tab, not Elements or Network.
- 2.When using Node.js, open the terminal in the same folder as your file, or the file will not be found.
- 3.Type commands exactly as shown, including spaces and lowercase letters.
Common mistakes
Typing JavaScript in the address bar
Avoid
Typing console.log("hi") in the URL barUse instead
Typing it in the Console tab after pressing F12The address bar expects a web address, not JavaScript. The console is the correct place to run code.
Running node without the file name
Avoid
node // opens a prompt and waitsUse instead
node hello.js // runs the fileTyping just node starts an interactive prompt. Add the file name so Node.js knows which script to run.
Quick tips
- •Try 10 * 10 in the console to confirm it works before writing any files.
- •Use the up arrow key in the console to bring back the last line you typed.
- •Write down the exact command that worked for you so you can repeat it later.