Book Image

Learn TypeScript 3 by Building Web Applications

By : Sebastien Dubois, Alexis Georges
Book Image

Learn TypeScript 3 by Building Web Applications

By: Sebastien Dubois, Alexis Georges

Overview of this book

TypeScript is a superset of the JavaScript programming language, giving developers a tool to help them write faster, cleaner JavaScript. With the help of its powerful static type system and other powerful tools and techniques it allows developers to write modern JavaScript applications. This book is a practical guide to learn the TypeScript programming language. It covers from the very basics to the more advanced concepts, while explaining many design patterns, techniques, frameworks, libraries and tools along the way. You will also learn a ton about modern web frameworks like Angular, Vue.js and React, and you will build cool web applications using those. This book also covers modern front-end development tooling such as Node.js, npm, yarn, Webpack, Parcel, Jest, and many others. Throughout the book, you will also discover and make use of the most recent additions of the language introduced by TypeScript 3 such as new types enforcing explicit checks, flexible and scalable ways of project structuring, and many more breaking changes. By the end of this book, you will be ready to use TypeScript in your own projects and will also have a concrete view of the current frontend software development landscape.
Table of Contents (15 chapters)

Installing Node.js and npm

In this section, we'll explain how to install both Node.js and npm on your machine.

Windows

Go to the official website of Node.js: https://nodejs.org and download the latest LTS (short for Long Term Support) release; you'll find the download links directly on the home page. This is preferred at work, but you may also install the latest and greatest.

For this book, we will be using 8.12.0 LTS, but newer versions should be okay.

Once downloaded, run the installer as follows:

  1. On the first screen, select where to install and click on Next:

On the next screen, make sure that npm package manager is selected so that npm gets installed as well.

  1. Also, check that Add to PATH is selected:
  1. On the next screen, click on Install:

The installation should then get going:

  1. Once completed, click on Finish:

Congratulations, you now have both node and npm on your machine.
In addition, Node.js also comes with a pre-configured shell called Node.js:

If you open up Command Prompt (for example, with cmd.exe), then you should be able to execute node and npm and retrieve their respective versions:

C:\Users\username>node --version
v8.12.0

C:\Users\username>npm
5.8.0

It should also work fine within PowerShell if you prefer that:

PS C:\Users\username>node --version
v8.12.0

PS C:\Users\username>npm --version
5.8.0

The exact version numbers don't matter that much as this evolves all the time, but if you want to be sure to have the exact same behavior, then you can try to match ours.

Git BASH

If you follow our advice and try to use Git BASH, then you might be disappointed at first.

Execute the following command:

$ node --version

When you do so, you should get back the following error: bash: node: command not found.

Changes to the Windows path are not immediately picked up by Git BASH; for this to happen, sometimes a reboot is necessary (Windows, eh?). If rebooting the operating system doesn't solve the issue, then you can also edit your user profile through the .bash_rc file and modify the path manually. For example, if you've installed Node.js under C:/nodejs, then you can add this to your Bash profile: PATH=$PATH:/c/nodejs. Once done, you should be able to execute both node and npm.

Linux (shell)

On Linux, the installation can easily be done using the Terminal with the following steps:

  1. First of all, open up the Terminal.
  2. Next, install curl as you'll need it to install Node.js: sudo apt install curl
  3. Then, install Node.js from the NodeSource (https://nodesource.com) repository:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
  1. You should now have both node and npm installed. Here's a link to the reference installation guide for Debian-and Ubuntu-based distributions: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions.
nvm (https://github.com/nvm-sh/nvm) is also a popular option to manage multiple node/npm installations.

Let's now see how to update npm.