/learn-node-js

A workshop to learn the fundamentals of Node.js

Primary LanguageJavaScriptMIT LicenseMIT

Learn Node.js {

A workshop for the Software Developers Club (SDC) at Queen's University

Contents

  1. Learning Goals
  2. Before We Begin
  3. Introduction
  4. Exercises
  5. Weather App
  6. Resources
  7. Next Steps
  8. License

Learning Goals

  • Become familiar with Node.js and its APIs.
  • Become familiar with NPM
  • Become familiar with Express.js
  • Learn how to consume a web API by making a weather appplication

Before We Begin

You must make sure that you have Node.js installed on your computer. In this workshop we will be using Node.js v6.9.2 LTS, but any version after that should work. To make sure that Node installed properly on your computer, you can check the version of Node that you are running using the following command from the command line:

$ node -v

Node.js installations also come with NPM, a package manager for JavaScript. Similarly to Node, you can make sure this installed correctly by checking the version you are running:

$ npm -v

You will also be making HTTP requests to the servers we create, so you will need a way to communicate those HTTP requests to the server. For GET requests, you can use your browser (everytime you navigate to a site with a browser it performs a GET request). For POST, DELETE, etc. requests you will need a library like cURL or a program like Postman. My personal recommendation is to use Postman since there is less of a learning curve if you are unfamiliar with CLIs.

API Keys

We will be using several APIs in this workshop, so you'll want to make sure that you have working API keys.

We will be getting weather data from OpenWeatherMap. You will need to sign up for an account to be able to access an API key.

We will also be using an API key for the Google Places API Web Service.

Get the API keys for both of those APIs and make note of them. We'll be using them for the final project.


Introduction

Node.js, as described on the Node.js website, is an "asynchronous event driven JavaScript runtime". Let's chop up this statement up into pieces to better understand what that means and explore a little deeper:

  • asynchronous: Node takes advantage of non-blocking I/O to ensure faster speeds when executing JavaScript code. This fancy language means that if a Node program needs to get information from another file on your computer or from an API on the internet, that it starts the request for information, but doesn't stop program execution to wait for the information to return. We'll talk more about this later. For more reading, see Node.js' Overview of Blocking vs Non-Blocking.
  • event driven: Node uses something called the event loop to allow for non-blocking I/O. Essentially, the event loop allows Node to unload I/O operations to the operating system so it can continue program execution. The event loop keeps track of I/O requests and resolves them when the request returns.
  • JavaScript runtime: Node is built on top of the V8 JavaScript engine (originally built for Google Chrome), which it uses to compile and run JavaScript programs.

JavaScript with Node compared to C/C++

Some languages like C/C++ require you to compile your programs before you run them. Node takes care of that for you by compiling your JavaScript to machine code before it executes it, all in one step.


Exercises

Each of the exercises is contained in the exercises directory. There are two folders for each exercise:

  • start : The boilerplate code necessary for the exercises is contained here. This is where you can write code as we progress through the workshop.
  • solution: This folder contains one possible solution to the problem. The solution in this folder is not necessarily the only possible solution, so keep that in mind.

You are now ready to begin!


Weather App

  • Read cities from a file
  • GET weather data for those cities
  • return data to be displayed on the client
  • if we add cities, write them to file
  • if we delete cities, rewrite the list to file.

API KEY in start.sh GOOGLE_MAPS_KEY in index.html

  • GET /api/cities
  • POST /api/cities
  • DELETE /api/cities

For the final project, we want to create a server that has 3 API routes that

Resources

  • http://node.green/ - Used to see what ECMAScript (e.g. ES6) features have been implemented in Node.js

Next Steps

License

2016 © Zack Harley

🍴Fork away!

}