Programming Refresher NodeJS
If you are completing this worksheet it is assumed that you are already familiar with both NodeJS and the Express
package that is used to build dynamic websites. This worksheet will serve as a refresher whilst learning how to use a technique called Test-Driven Development which you will need to apply on a regular basis during the remainder of this module.
If you are not familiar with NodeJS and Express ask your lab tutor for additional resources.
Navigate to the exercises/01_tdd_nodejs
directory and open the package.json
file. Notice that there are certain modules listed as dependencies and others labelled as devDependencies. Use the npm install
command to install all of these.
If you examine the folder structure you will see that there are several directories:
- The
modules/
directory contains the three modules that will contain the business logic plus a__mocks__
directory that we will be exploring at a later stage. - The
__tests__/
directory contains test scripts that matche each of the modules - The html directory contains the page templates used by the express renderer
- The public directory contains files that can be directly accessed by the web server
├── __tests__
│ ├── books.test.js
│ ├── google.test.js
│ └── utility.test.js
├── html
│ └── index.html
├── index.js
├── modules
│ ├── __mocks__
│ └── google.js
│ ├── books.js
│ ├── google.js
│ └── utility.js
├── node_modules
├── package-lock.json
├── package.json
└── public
└── style.css
Start the web server using node index.js
and access the URL (this will be localhost:8080
if you are running it on your workstation).
│ │ └── __mockData__
│ │ ├── 9781785885581.json
│ │ ├── 9781785885587.json
│ │ ├── extractedData.json
│ │ ├── java.json
│ │ ├── req.json
│ │ └── validTable.txt
TDD
7 Preparation
You will need to ensure your skills are up to date before we begin preparation in week 3.
7.2 API Team
- Subscribe to an MQTT data feed on Adafruit using NodeJS and print data to terminal. There is a good online tutorial to get you started.
- Build an MQTT server. Heroku offer a free hosting option
7.3 Front End
- Get familiar with the mapping APIs! (Google Maps / Apple Maps)