Node.js Workshop

This workshop will review the concepts covered in the Node.js lecture and go through the process of initializing, editing, and updating a Node.js application.

If you have any trouble with the workshop, raise your hand and one of the staff will be happy to help you.

Parts I and II are not intended to be completed by everyone. Instead, follow along with the lecturer, ask questions, and make sure you understand what's going on.

Part I

We'll do these together:

  1. Create a hello-world Node script
  2. Create a hello-world Node+Express app with help from express-generator using the command express --hbs
  3. Understand the project directory structure:
    • package.json, node_modules
    • app.js
    • README.md
    • bin, routes, views, public

Part II

First, clone the starter code from the GitHub repository at go.6148.io/nodejs-starter. (Open the repository web page, copy the SSH clone URL from the right-hand side of the page. In your terminal, navigate to the desired folder and run git clone <url_here>).

We'll do these together:

  1. Print a message to the console when you load the root page
  2. Add some color to the console message with chalk
  3. Manually (in routes/index.js) add an entry to the in-memory "database"
  4. Get the add a user form working (adding a user to the database)

Part III

Now try doing the following exercises:

  1. Get the delete a user form working (removing a user from the database)
  2. Get the search for a user form working (searching for a user in the database--if found, return their fruit; if not found, return an error message)
  3. Add a new route that prints a random ASCII cat to your device console (not the browser console). Use the cat-me npm package. (Don't worry if visiting the route prints multiple cats--this can be caused by browser prefetching.)

Solutions

See go.6148.io/nodejs-solutions for solutions.