This is a good example of an online IDE. These enable you to do software development without needing to install anything on your computer. They are also ideal for use with a Chromebook. You need to sign up for an account on their website, sign in and access the dashboard page. Click on the Create a New Container button.
You will be presented with a screen where you can name your project and choose a software stack:
You should see an IDE that displays the files down the left side with an editor in the main view and a terminal window below:
The lab materials are in a repository on the University GitHub server. We need to make a copy of this repository by forking it, then clone it into Goorm.io, follow the instructions below carefully.
You should start by logging in to the University GitHub server using your university username and password. Make sure you don't log into GitHub.com!
Next you should open the web page containing the 205CDE teaching materials and click on the small Fork button in the top-right corner of the page.
You will be asked to select where you want to place the forked repository, make sure you choose your own personal space (the one that is named using your username).
This will create an exact copy (clone) of the repository in your personal workspace. It should indicate where the original version was (see below).
The next step is to clone the forked repository containing the lab materials into the IDE. Locate the Clone or download button, clicking this pops open a small window as shown. Copy the URL in this window to your clipboard.
Returning to the IDE, run the following command in the terminal, the url to your forked repository should already be in the clipboard:
git clone https://github.coventry.ac.uk/xxx/TEACHING-MATERIALS.git labs
This creates a labs/
directory containing all the files from your forked repository.
Your forked repository is a snapshot of the contents of the original one. The problem is that the repository you forked (called the upstream repo) will be updated on a regular basis and we need to ensure these changes are pulled into your fork.
To do this we need to add a link to this repository and use this to pull new content down. Follow these instructions carefully:
- Make sure you have the terminal window open and have navigated to inside the
labs/
directory. A quick check is to use thepwd
command, the folder path should end with/labs
. You may need to use thecd labs
command to get to the right place. - Now you need to add the upstream remote using the
git remote add upstream https://github.coventry.ac.uk/205CDE-1819JANMAY/TEACHING-MATERIALS.git
command. - Finally we should check we have links to both the original repository and our fork using the
git remote -v
.
Before you can work with Git you need to update the repository configuration. Follow the instructions below:
- Update your name (this must be the name as it appears on your ID badge) using
git config user.name 'Joe Bloggs'
. - Update your email (using your unversity email)
git config user.email 'bloggsj@uni.coventry.ac.uk'
- Update your commandline editor choice using
git config core.editor nano
(the editor must be installed!) - Cache your credential (username/password) for an hour using
git config credential.helper 'cache --timeout=3600'
- Update the path to your git hooks directory using
git config core.hooksPath ./.githooks
(more on this in a later lab).
By default real-time linting is enabled however this currently uses an old linter and is not ECMA6 compatible. You should disable real-time linting from the Project menu.
We can see the current version of NodeJS by running the node -v
command. The latest version is 10.11.0 and so we need to upgrade this.
Start by installing the Node Version Manager tool:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Now click on the small blue oval on the terminal tab to reload the shell. There are lots of versions available, use the nvm list-remote
command to see these. Install the latest using nvm install 10.11.0
substituting the latest version number. To check the version installed use node -v
again.
Use the terminal to navigate to the exercises/01_http/
directory and try running the index.js
script:
$ cd exercises/01_setup/
$ node index.js
Error: Cannot find module 'koa'
Notice you get an error, we need to install the missing module using the Node Package Manager tool. We can then try to run the script again:
$ npm install koa
$ node index.js
app listening on port 8080
Now we have the server up and running so the final task is to view the web page using the web browser.
This will open a window where you will need to register a new URL and port:
- Use your University Username as the URL segment.
- Make sure you specify port 8080 (this is the one used by your server).
You need to set this up as your run configuration as shown.
The final step is to open a new browser window and enter your chosen URL, you don't need to specify the port, this was done through port-forwarding:
If you make changes to the code or want to quit the IDE you will need to stop the server. To do this, select the terminal window and press ctrl+c.
If you are planning on using your own laptop you will need to install some key pieces of software. Obviously its impossible to cover the installation process in detail for every operating system but there are plenty of guides online. You should install:
- Visual Studio Code (Not Visual Studio!)
- The latest version of NodeJS. For Linux follow the instructions to install nvm, for other platforms download and install the latest version from the official site, make sure you install the latest and not the LTS version.
- You also need to install Git if it is not already installed. Mac and Windows users can download the installer from the official website.
Once everything is installed you can clone the module repository using the same command you used in the Goorm IDE lab (make sure you clone it to a sensible location).
Once the repository is cloned you should open VS Code and use the File > Open Folder option to select and open the folder containing the repository (On some systems you choose File > Open).
Once the web server is up and running you access the page by pointing the browser to localhost:8080
.
As we develop more complex web apps it becomes more and more difficult to fully test our app every time we change the code. By not testing everything at regular intervals there is an increasing chance that our new code could break the existing code in our system. Since regular testing is a chore, programmers have developed ways to automate this process.
In this section you will be given a sneak preview of how an automated test suite works. We will be using a testing framework developed by Facebook, called Jest and will be using a second tool called Supertest which allows us to interact with our code using http.
The process requires you to install both these packages and then run the jest
command:
$ npm install jest supertest
$ ./node_modules/.bin/jest
PASS .test/index.test.js
GET /
✓ the page should return a status code of "200 OK" (25ms)
✓ we should see the text "Hello World" displayed (3ms)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.478s
Ran all test suites.
If you study the test output carefully you will notice that there is a test script .test/index.test.js
which contains 2 tests in 1 test suite. Each test has a name and the ticks indicate that both tests have passed.
It is possible (and desirable) to run the test suites every time you save any changes to your app. Testing tools such as Jest support a watch mode that detects if files have changed and automatically runs the full test suite if this happens:
./node_modules/.bin/jest --watch
To exit watch mode press (ctrl+c).
Make sure that you are running Jest in watch mode.
- Modify the
index.js
script so that the web page displays your name. - The unit test suite will be triggered by you saving your changes. Read the output carefully.
- Modify the test suite so that it is looking for the text
My First Tests
. - The unit test suit will be triggered again, note that one of the tests has still failed.
- Modify the
index.js
file to make the test suite pass.