We're going to set up a few things so you have a neat development environment on your computer with a good CLI (command line interface). You will need administrator access to your computer for some parts of this. Make sure you follow the correct sections/lines for the OS you're on, whether Windows, Linux, macOS or WSL.
Windows comes with PowerShell 5, but PowerShell 7+ includes useful features like completion suggestions to make working on the CLI better. Here's how to upgrade:
$PSVersionTable.PSVersion (skip to the next section if it reports version 7+ already)winget search Microsoft.PowerShell to see the latest PowerShell versionwinget install --id Microsoft.PowerShell --source winget to update to the latest stable versionOpen the 'Terminal' app on your OS.
When opened, you'll see a black window, which is called a terminal or command line interface (CLI).
You can run commands and programs from the command line by typing them and pressing enter. Some commands are slightly different depending on your OS. Here are some to try out now (they should work on all OSes):
ls will show you files in the current folder (which might be empty)pwd shows you the full path to the folder you're currently inmkdir blah will make a new folder called 'blah'cd blah will take you into the folder you just made called 'blah'touch hello.txt will make a new file called 'hello.txt'
ni hello.txt insteadecho 'hello world' > hello.txt will put the text 'hello world' into that filecat hello.txt will show you the contents of 'hello.txt'clear clears the screendate shows you the datecurl https://news.ycombinator.com/ -o page.html gets the contents of a web page and outputs it into a local file (read it with cat page.html or open it in a browser)cd .. takes you up a folder levelSome tricks and tips to save you a lot of time when you're on the command line:
q or CTRL+C, depending on the programOptional extension: search the web for eg 'Linux commands' or 'PowerShell commands' to find some more commands to try out.
We'll be using VSCode as our code editor and integrated development environment (IDE) (well, technically it's not quite an IDE but a 'code editor' instead).
A classic dilemma for programmers: should you use 2 spaces, 4 spaces or tabs to indent? Countless hours and sleepless nights have been lost to this classic bike-shedding problem. But I'll solve it for you - you'll use 2 spaces, because that's what I use, because reasons. End of.
Set up VSCode to respect this decision:
CTRL+, (or CMD+, on macOS)When you're writing code, it's easier if everyone is using the same folder name - a folder called 'code' in your home folder.
CTRL+')/home/[name] on Linux/WSL/macOS or C:\Users\[name] on Windows) in the terminalmkdir codecd codeJavaScript was originally made for running in web pages, but can now be used on the command line (CLI) as well. Today we'll be using it on the CLI, then will use it for websites in a few weeks. There are 3 main CLI options for running JavaScript: Node.js, Deno and Bun. We use Bun.
Install Bun by opening a terminal within VSCode and running:
Linux, macOS and WSL:
sudo apt install unzip (macOS already has this installed)curl -fsSL https://bun.sh/install | bashWindows PowerShell:
powershell -c "irm bun.sh/install.ps1 | iex"... when installed, close VSCode completely, then reopen it.
Check it is working by running bun, which should show you some usage information. Find what version you're running with bun --version.
Try some JavaScript using Bun's REPL (read-eval-print loop) with bun repl (remember you can exit any time with CTRL+C). If it asks something about a firewall, click to allow. Here are some things to try from within the REPL:
3 + 44 * 5let x = 4 ** 5 makes a variable called 'x' holding the result of 4 to the power of 5x + 1.help will show you REPL usage infofor (let i = 0; i < 5; i++) console.log(i) will run a loop'hello' shows the string 'hello'let place = 'world' makes a variable called 'place' with the string 'world' in it`Hello ${place}` outputs 'Hello world', though make sure you're using backticks (left of the '1' key on the keyboard)Remember to exit with CTRL+C.
You can also run any of the above with simply bun -p '3 + 4' etc. The -p flag is short for 'print'.
First, macOS users need to add a handy alias first so they can type code [filename] to edit a file in VSCode:
CTRL+SHIFT+Psource ~/.zshrcFrom inside a terminal within VSCode (all users now):
mkdir -p ~/code/hello-world to make a sub-folder called 'hello-world' in a folder called 'code' in your home folder, which is aliased as '~'cd ~/code/hello-world to go into the folder you just madecode hello.js will open a new file in this folder called 'hello.js' in the text editorYou should now have a new file called 'hello.js' open in VSCode. Add console.log('Hello world') to the file, then save it.
Jump back into the terminal and run bun hello.js to run your JavaScript file.
That's the end of this guide. Next up, you'll be learning about JavaScript!