Welcome to the Code the Dream’s first ever Node/Express class, Alpaca!
Node, short for Node.js, is an implementation of the Chrome JavaScript engine, but one that runs outside of the browser, so that it can be used to write standalone programs as well as web serving applications. Express is a framework for Node that makes the creation of web applications very easy. These are complemented by a vast library of NPM packages to make adding common functions easy. The combination is a leading framework throughout the IT industry, and continues to grow in adoption. And, all programming in Node and Express is in JavaScript, so the back end engine for an application can be written in the same language as the front end.
Remember you can always use your class discussion channel (#alpaca-discussion) if you need help throughout this course. The Student Resources page also has links to git cheat sheets, documentation and more.
Course Calendar
Week | Start Date | Due Date | Lessons |
Pre-Class | 06/01/2022 | 06/07/2022 | Machine Setup Github Cookbook |
Week 1 | 06/08/2022 | 06/14/2022 | Node Introduction |
Week 2 | 06/15/2022 | 06/21/2022 | NPM and Async Patterns |
Week 3 | 06/22/2022 | 06/28/2022 | Introduction To Express |
Week 4 | 06/29/2022 | 07/05/2022 | Middleware, REST Methods, and Postman |
Week 5 | 07/06/2022 | 07/12/2022 | Task Manager API Part 1 |
Week 6 | 07/13/2022 | 07/19/2022 | Task Manager API Part 2 |
Week 7 | 07/20/2022 | 07/26/2022 | Using Query Parameters |
Week 8 | 07/27/2022 | 08/02/2022 | JWT Basics |
Week 9 | 08/03/2022 | 08/09/2022 | Jobs API Part 1 |
Week 10 | 08/10/2022 | 08/16/2022 | Jobs API Part 2 |
Week 11 | 08/17/2022 | 08/23/2022 | Catch Up Week Mindset Assignment Link |
Week 12 | 08/24/2022 | 08/30/2022 | A Front End for the Jobs API |
Week 13 | 08/31/2022 | 09/06/2022 | Server Side Rendering with EJS |
Week 14 | 09/07/2022 | 09/13/2022 | Authentication with Passport |
Week 15 | 09/14/2022 | 09/20/2022 | Testing with Mocha and Chai |
Week 16 | 09/21/2022 | 09/27/2022 | Final Project Begins Mindset Assignment Link |
Week 17 | 09/28/2022 | 10/04/2022 | Final Project Completed |
Week 18 | 10/05/2022 to 10/07/2022 | Time TBD | Final Project Presentations |
For the final project, each student implements an Express application that includes authentication and CRUD operations to a MongoDB database. The application may be implemented as APIs plus a front end (full stack) or using Server Side Rendering with EJS templates. The rubrics for each are below:
Rubric for Express Server Side Rendering
On Structuring Your Final Project
Code for the Express final project should be organized in the following way: There should be the following directories:
- models
- routes
- controllers
- middleware
- db
In addition, server side rendering projects should have views/pages and views/partials. Some projects may have static pages, which should be in the public directory. For both back end and server side rendering projects, there should be error handling, page not found, and authentication middleware. You should have a .env file with project secrets such as the database URI with the password, the JWT secret if JWT is used, and the session secret for server side rendering. Again, never put these secrets in the code, and make sure .env is in your .gitignore file before you push your project to Github.
A sample project that is organized in this way is here. The lessons on server side rendering and passport did not follow this organization model — although I may fix this for subsequent classes. The example linked above does use server side rendering and passport, so this example is particularly important for people doing server side rendering projects. Note that the bcrypt functions are moved into the User model. Note also that the comparePassword function provided is not asynchronous, as it is for the Jobs API project, because Passport can’t call an asynchronous function. Instead we use callbacks. The example I provide does not include partials, although it probably should.
The example also is not secure for Internet deployment. We haven’t talked about that much, but I hope to remedy that with additional material I will post.
This project organization is not strictly required for final projects but it is strongly recommended.
I also have added two new packages, eslint and prettier. Eslint finds syntax errors, where the code may work but really isn’t written right. Prettier reformats the code so that it looks more readable. I have configured these with .eslintrc.json and .prettierignore. These packages are part of the standard build process for production Express applications. You do not have to use them, but you may find them useful, and you should learn to use them eventually. You can run eslint on the sample package with:
npx eslint .
to find syntax errors you need to fix, and you can run prettier as follows:
npx prettier . --write
The prettier command above actually rewrites the files to make them look more readable. As it rewrites everything, you should do your prettier operation in a separate branch, which you then test and merge into the main branch.