Chapter 1 Getting Setup

This course will cover a wide variety of tools and techniques used in modern web development, including different software programs that are used to write, manage, and execute the code for your web application. This chapter explains how to install and use some of the software you will need to utilize.

Note that iSchool lab machines should have all appropriate software already installed and ready to use.

In summary, you’ll need to install and set up the following software on your machine (more information below on each of these). Feel free to use alternative software, but these are the suggested programs for the course (i.e., the ones which we will provide support for):

  • A modern web browser such as Google Chrome
  • Visual Studio Code as your code editor
  • Node.js as a JavaScript engine
  • npm as a JavaScript package manager (comes with Node.js)
  • git as a version control system (for Windows users; already installed on Macs)
  • A Bash terminal (e.g., the Git Bash for Windows; Terminal is already installed on Macs)

1.1 Web Browser

The first thing you’ll need is a web browser for viewing the web pages you make! We recommend you install and utilize Chrome, which comes with an effective set of built-in developer tools that will be especially useful in this class. We recommend Chrome primarily for historical reasons (and because it is the browser used by the authors—and we had to pick one!)

  • You can access the Chrome Developer tools by selecting View > Developer > Developer Tools from Chrome’s main menu (cmd + option + i on a Mac, ctrl + shift + i on Windows). You will pretty much always want to have these tools open when doing web development, especially when including interactivity via JavaScript.

Other modern browsers such as Firefox or Microsoft Edge will also function perfectly well in this course and include their own versions of the required development tools. Note that different browsers may and will render code in different ways, which will be discussed extensively throughout the course.

We strongly suggest that you don’t use Safari, as it has a number of user interface and rendering issues that make it difficult to develop with for this course.

1.2 Code Editors

In order to write web code, you need somewhere to write it. There are a variety of code editors and IDEs (Integrated Development Environments) that are specialized for web development, providing syntax highlighting, code completion, and other useful functionality. There are lots of different code editors out there, all of which have slightly different appearances and features. You only need to download and use one of the following programs (we recommend Visual Studio Code as a default), but feel free to try out different ones to find something you like (and then evangelize about it to your friends!)

Visual Studio Code

Visual Studio Code (or VS Code; not to be confused with Visual Studio) is a free, open-source editor developed by Microsoft—yes, really. It focuses on web programming and JavaScript, though also supports many other languages and provides a number of community-built extensions for adding even more features. Although fairly new, it is updated regularly and has has become one of our main editors for programming. VS Code is actually a stand-alone web application, so it’s written in the same HTML, CSS, and JavaScript you’ll learn in this course!

To install VS Code, follow the above link and Click the “Download” button to download the installer (e.g, .exe) file, then double-click on that to install the application.

Once you’ve installed VS Code, the trick to using it effectively is to get comfortable with the Command Palette. If you hit cmd + shift + p, VS Code will open a small dialog where you can search for whatever you want the editor to do. For example, if you type in markdown you can get list of commands related to Markdown files (including the ability to open up a preview). The Format Code option is particularly useful.

For more information about using VS Code, see the documentation, which includes videos if you find them useful. The documentation for programming in HTML, CSS, and especially JavaScript also contain lots of tips and tricks.

While we suggest using VSCode for this course, other editors are also acceptable and may be of interest to you.

Atom

Atom is a text editor built by the folks at GitHub and has been gaining in popularity. It is very similar to VS Code in terms of features, but has a somewhat different interface and community. It has a similar command-palette to VS Code. The document you are reading was authored in Atom.

Brackets

Brackets is a coding editor created by Adobe specialized for client-side web developers. It has some intriguing features that are not yet in Visual Studio Code, as well as possibly the nicest interface of this list.

Sublime Text

Sublime Text is a very popular text editor with excellent defaults and a variety of available extensions (though you’ll need to manage and install extensions to achieve the functionality offered by other editors out of the box). While the software can be used for free, every 20 or so saves it will prompt you to purchase the full version. This is a great option to write a plain text file.

1.3 Bash (Command Line)

Many of the software tools used in professional web development are used on the command line: a text-based interface for controlling your computer. While the command line is harder to learn and figure out, it is particularly effective for doing web development. Command line automation is powerful and efficient enough to handle the dozens of repeated tasks across hundreds of different source files (split across multiple computers) commonly found in web programming. You will need to be comfortable using the command line in order to utilize the software for this course.

While there are multiple different command shells (command line interfaces), this course uses the Bash shell, which provides a particular common set of commands common to Mac and Linux machines.

On a Mac you’ll want to use the built-in app called Terminal. You can open it by searching via Spotlight (hit Cmd () and Spacebar together, type in “terminal”, then select the app to open it), or by finding it in the Applications/Utilities folder.

  • As of macOS Catalina, Macs use zsh as the default command shell with Terminal. This works mostly the same as bash (supporting generally the same command). It is also possible to switch between the two shells if needed.

On Windows, you can use the Git Bash shell, which you should install along with git (see below). Open this program to open the command-shell.

  • Note that Windows does come with its own command-prompt, called the Command Prompt (previously the DOS Prompt), but it has a different set of commands and features. Powershell is a more powerful version of the Command Prompt if you really want to get into the Windows Management Framework. But Bash is more common in open-source programming like we’ll be doing, and so we will be focusing on that set of commands.

  • Alternatively, you can set up the Windows Subsystem for Linux (WSL). This will let you turn the Windows command prompt into a full-blown Bash shell just by typing the command bash. (Technically you’re running a small copy of the Linux operating system inside of your Windows install, but we’re just going to need the Bash shell). Follow the linked instructions for installing this system. Note that you’ll need to pay attention to file paths if you use WSL, as by default the current working directory is set to the Linux partition rather than your Windows partition.

This course expects you to already be familiar with basic command line usage. For review, see The Command Line in the INFO 201 course reader.

1.4 Git and GitHub

Professional web development involves many different people working on many different files. git is a collaborative version control system that provides a set of commands that allow you to manage changes to written code, particularly when collaborating with other programmers.

You will need to download and install the software. If you are on a Mac, git should already be installed. If you are using a Windows machine, then installing git will also install the Git Bash command shell.

Note that git is a command line application: you can test that it is installed by running the command:

git --version

While git is the software used to manage versions of code, GitHub is a website that is used to store copies of computer code that are being managed with git (think “Imgur for code”).

In order to use GitHub, you’ll need to create a free GitHub account, if you don’t already have one. You should register a username that is identifiable as you (e.g., based on your name or your UW NetID). This will make it easier for others to determine out who contributed what code, rather than needing to figure out who ‘LeetDesigner2099’ is. This can be the start of a professional account you may use for the rest of your career!

This course expects you to already be familiar with utilizing Git and GitHub. For review, see Git and GitHub, Git Branches, and Git Collaboration in the INFO 201 course reader. Note that students in the INFO 340 course will be using GitHub and Pull Requests to turn in programming assignments.

1.5 Node and npm

Node.js (commonly just “Node”) is a a command line runtime environment for the JavaScript programming language—that is, a program that is used to interpret and execute programming instructions written in JavaScript. Although client-side development usually involves running JavaScript in the browser (see Chapter: JavaScript), Node provides a platform for installing and running a wide variety of “helper” programs that are frequently used in web development.

The easiest way to install Node is to use the installer from Nodejs.org. I recommend getting the latest version for this course. Download the installer and execute it to set up Node on your machine.

  • If you want more control over your machine and Node versions, you can alternatively install Node using nvm, the Node Version Manager. This is a command line program that manages installing the Node command line program, but also makes it easy to update or adjust your Node installation. (It also installs the same way on Mac or Windows WSL). See the installation instructions for details.

You can test that Node is installed and working by opening your command shell and running

node --version

Be sure and check that you have a recent enough version! At time of this writing, you should have Node v17 or later.

Installing Node also installs an additional command line program called npm. npm is a package manager, or a program used to “manage” other programs—think of it as a command line “app store” for developer tools and libraries. npm is the most common way of installing and running a large number of tools used in professional web development. At the time of writing, the npm “registry” lists around 725,000 different packages.

If you have an older version of Node and npm (before Node 10.16 or npm 5.6), you will need to update them. You can re-install the latest version of Node as above, or just upgrade npm using the command npm install npm@latest -g. See below for an explanation of this command.

Managing packages with npm

You can use the npm program to download and install command line programs by name:

# syntax to globally install package with npm
npm install -g PACKAGE-NAME

For example, you could install the Jest testing application (a program for running automated tests) used in this course using:

# globally install the Jest package
npm install -g jest

Importantly, note the included -g option. This tells npm that the package should be installed globally, making it available across the entire computer, rather than just from a particular folder. Because you want to be able to use a command line program like Jest from any folder (e.g., for any project), command line utilities are always installed globally with the -g option.

Installing an application globally requires administrator permissions. If you try to install something without admin permission, you’ll get an error saying permission denied:

A permission denied error when installing with npm

In order to install programs globally, you will need to use the sudo (superuser do) command to run the install as an administrator. You do this by putting sudo in front of the command you want to run, for example:

# as an administrator, globally install the Jest package
sudo npm install -g jest

You will be prompted for your computer’s password, make sure to fill that in (even though you won’t see any typing occur).

Note that you should only use sudo when necessary (e.g., when you hit this error); don’t run every command as an administrator!

After an application is installed, you can run it from the command line by typing the name of that program followed by any arguments. For example, you can have the Jest program print it’s version:

# get the version of the installed Jest application
jest --version

The latest version of npm also comes with an additional program called npx. This application lets you “download and run” an application with installing it separately. For example, you could download and run Jest to see it’s version:

# download and run the Jest application without installing it separately
npx jest --version

It is also possible to install packages locally by omitting the -g argument. For example:

npm install lodash

Will download the lodash code library (a set of useful JavaScript functions). This package will be placed into a new folder in the current project directory called node_modules/, and can be imported and used in the current directory’s code. (It’s called a local install because the package is only available to the “local” project). You will of course need to install local packages once per project.

Because node packages can be very large, and projects can have lots of them, you want to be sure to not commit the node_modules/ folder to version control. Make sure that the folder is listed in your .gitignore file!

package.json

As projects become large, it is common for them to build up many dependencies: packages that must be installed in order for the program to work. In other words, there needs to be a certain set of packages in the project’s node_modules/ folder. npm is able to keep track of these dependencies by recording them in a specialized file called package.json that can be placed inside the project directory. A package.json file is a text file containing a JSON list of information about your project. For example:

{
  "name": "example",
  "version": "1.0.0",
  "private": true,
  "description": "A project with an example package.json",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "Joel Ross",
  "license": "ISC",
  "dependencies": {
    "lodash": "^4.17.4",
    "moment": "^2.18.1"
    },
  "devDependencies": {
    "html-validator": "^2.2.2"
  }
}

(You can create one of these files by using the command npm init in the current project directory, and then following the instructions to fill in the fields).

Notice that there are two packages listed under "dependencies": lodash and moment (the ^4.17.4 indicates which version of lodash). You can use npm to automatically install all of the packages listed under "dependencies" (as well as under "devDependencies") using the command:

npm install

Thus using npm install without any arguments means “install all of the requirements that have been listed for this project”. This is a good first step any time you download a project or checkout a repository from GitHub.

When installing specific packages, npm automatically adds them to the dependencies list in the package.json, though you can make this explicit with the --save option:

# explicitly save dependency in package.json
npm install --save lodash

Similarly, the --save-dev option will instead save the package in the "devDependencies" list, which are dependencies needed only for development (writing the program’s code) and not for execution (running the program).

You can uninstall packages using npm uninstall, or can remove packages from the dependencies lists simply by editing the package.json file (e.g., with VS Code).

To sum up, you will use three commands with npm to install packages:

  1. npm install -g PACKAGE-NAME to globally install command line programs.
  2. npm install to locally install all of the dependencies for a project you check out.
  3. npm install PACKAGE-NAME to locally install a new code package and record it in the package.json file.

While npm is the most popular package manager (and the one utilized in this course), there are others as well. For example, Yarn is a package manager created by Facebook that is compatible with npm and is quickly growing in popularity. Note that you will generally need to use one package manager or other; don’t try to mix them in a single project!

Resources

Links to the recommended software are collected here for easy access: