Coding ยท ยท

Setting up your development environment

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-only: get the latest PowerShell

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:

Getting familiar with the command line

Open 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):

Some tricks and tips to save you a lot of time when you're on the command line:

Optional extension: search the web for eg 'Linux commands' or 'PowerShell commands' to find some more commands to try out.

VSCode

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).

2 spaces indentation

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:

Getting a folder ready for all your code

When you're writing code, it's easier if everyone is using the same folder name - a folder called 'code' in your home folder.

Bun JavaScript runtime

JavaScript 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:

Windows PowerShell:

... 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:

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'.

Creating your first JavaScript program

First, macOS users need to add a handy alias first so they can type code [filename] to edit a file in VSCode:

From inside a terminal within VSCode (all users now):

You 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!