- Learning Objectives
- Suggested Study
- Sundays & Projects
- Class Recordings
- Curriculum (external)
- HYF Home (external)
expand/collapse
- Comfortably work with the file system
- Explain "persistence"
- Build basic fullstack projects (SPA/API) that save to the file system
- Write RESTful APIs for simple data relationships
- Using NPM Packages in your projects
- Using Postman to develop APIs without a frontend
- Running and writing tests for API routes
- Documenting your code with JSDoc
- Node.js CLI scripts
- argsv - Use command line arguments in Node
- Native Node.js modules
- assert - Test values in Node.js
- fs - Read & write form the file system
- path - Manipulate file paths
- util.promisify - Convert functions that take callbacks into Promises
- for fun:
- cowsay - make cows say things
- for serious:
- node-fetch - Make API requests from Node
- express - Minimalist web framework for node
- body-parser - Parse HTTP request body into JS object
- cors - Cross Origin Resource Sharing for Express
- morgan - logging for Express
- joi - JSON schemas & validation
Projects in this module will build on what you learned in the last module by adding in network calls to APIS and scheduled tasks on the event loop.
References and Practice to help you master this module.
expand/collapse
- Getting started with Node.js debugging in VS Code
- Burke Holland
- VSCode Channel Intro
- James Q Quick
- CodeSpace, 2 Ways
- 101
- Built-In Modules
- About /examples-and-exercises:
fs
(first 20 minutes) - promisifying-fs
- About /examples-and-exercises:
- CLIs
- cowsaydex
- Practice using NPM Packages into your projects, starting with cowsay
- node-practice-replace
- cowsaydex
- API Calls
- node-fetch: a module for using
fetch
syntax in Node.js - To study a full app with
node-fetch
, head over to weather-it-promised & weather-it-async-await - node-fetchemon (exercises to practice
node-fetch
)
- node-fetch: a module for using
- HTTP Status Code: HTTP Request Status Code Guide
- Middleware: tutorialspoint, express.js guide, writing middleware (video)
- Static Serving: alligator article, codedamn video
- Error Handling Middleware:
- CORS: Cross Origin Resource Sharing
- HTTP Statuses
- Traversy: Express.js Crash Course
- How To Build a Job Search App (Node, APIs, Vanilla JS): video, code
- Error Handling
Router
- pokedex-api
config
file: how to
- The Docs
- a video
- Schema Validation
- jsonschemavalidator.net (used in the prep videos)
- tv4 validation library (prep video and your projects)
Directly from GitHub
From Terminal
- Heroku Getting Started
- Scotch Tutorial
- Heroku devhints
- Heroku DevCenter: Node.js Support
- Heroku DevCenter: Advanced Automation
Founders and Coders is another open-source course in web development. They have some great resources for learning Node, Express and Web Apps
In Class: File system I/O & basic Node.js CLI programs
At Home: Express APIs that access the file system
expand/collapse
- Week 1 Prep Video
- Running .js files in Node
process.argv
assert
fs
- Have Node
- Install NVM (node version manager)
- Make sure you have the latest Node.js installed (14..)
- VS Code Debugger
- Error-First Callbacks
- fredkschott (article)
- Sid Harder (video)
- David Connelly (video)
/examples-and-exercises
-
- Modules (examples)
-
process.argv
(example.js)
-
fs
Sync (examples)
-
during class
- all together: Class Slides
- in groups: 04-fs-sync
- 05-fs-async
- examples: all together
- exercises: in groups
Not required, but it will help.
Group Project, Code-Along
This week's project is to follow the Build RESTful APIs with Node and Express by Mosh. Besides just Express and writing RESTful routes you will learn how to use JSON schemas, test your API's with Postman, use environmental variables-, and practice continuous development using _nodemon.
Don't worry if you don't understand everything in this project. The tutorial covers a lot of material very quickly, we'll spend the next weeks going deeper into the topics Mosh covers here. Think of this week's project as a sneak preview of the coming 3 weeks.
Just copying his code is not all! After finishing with the tutorial you will need to refactor the code so that It reads and writes from a file called courses.json
instead of using a local variable. ie:
-
app.post('/api/courses', (req, res) => { const { error } = validateCourse(req.body); if (error) return res.status(400).send(error.details[0].message); const course = { id: courses.length + 1, name: req.body.name, }; courses.push(course); res.send(course); });
-
// there are some mistakes in this, we can't give it all away ;) app.post('/api/courses', (req, res) => { const { error } = validateCourse(req.body); if (error) { return res.status(400).send(error.details[0].message); } fs.writeFile(COURSES_PATH, (err, content) => { if (err) { res.status(500).send(err.message); return; } const parsedCourses = JSON.stringify(content); const course = { id: courses.length + 1, name: req.body.name, }; parsedCourses.push(course); const stringifiedCourses = JSON.parse(parsedCourses, null, ' '); fs.readFile(COURSES_PATH, parsedCourses, err => { if (err) { res.status(500).send(err.message); return; } res.send(course); }); }); });
And here's a suggestion for how to organize your courses.json
file:
{
"nextId": 3,
"courses": [
{
"id": 0,
"name": "x-ray"
},
{
"id": 2,
"name": "gamma-ray"
}
]
}
You will be expected to turn in your code from his tutorial on a new repository called restful-courses
. you will be assessed not only on your live demo, but also on the quality of your code, the correctness of your branches, the organization of your code, and the completeness of your README. Your repo must include:
- [ ] [repo](https://github.com/_/_) (with a complete README)
- [ ] [live demo](https://_.github.io/_)
- Project Planning
- [ ] [Backlog](https://github.com/_/_/tree/master/project-planning/backlog.md)
- [ ] [Development Strategy](https://github.com/_/_/tree/master/project-planning/development-strategy.md)
- [ ] [Project board](https://github.com/_/_/projects/_)
- Implementation
- [ ] API data is saved in `courses.json`
- [ ] Deployed - [deployment url]()
APIs & Client/Server web apps
expand/collapse
- Slides: live
- Examples & Exercises: 07-express-static-serving
- Recordings: Part 1, Part 2, Part 3
- About Servers
config
file: how to- HTTP Statuses
- all together: Class Slides
- in groups: 08-express-dynamic-serving
- 09-params-queries-body
- examples: all together
- exercises: in groups
It's not required, but it will help.
DIY Wiki: Starer Code (Individual Project)
This week's project is to complete the code in the diy-wiki
repository.
- [ ] [repo](https://github.com/_/_) (with a complete README)
- [ ] [live demo](https://_.github.io/_)
- Project Planning
- [ ] [Backlog](https://github.com/_/_/tree/master/project-planning/backlog.md)
- [ ] [Development Strategy](https://github.com/_/_/tree/master/project-planning/development-strategy.md)
- [ ] [Project board](https://github.com/_/_/projects/_)
- Implementation
- [ ] Deployed - [deployment url]()
- HTTP status codes
- Error handling middleware
- Separating concerns in Node/Express servers
- Using Express Routers to write modular servers
expand/collapse
- slides
- videos: Part 1, Part 2, Part 3
- Examples: 10-refactoring-apis
- Express Router
- Express Error Handling
Practice refactoring small Express apps from single-file servers into multiple files using express.Router()
.
- all together: Class Slides
- in groups: 10-refactoring-apis
- 11-middleware-and-error-handling
- examples: all together
- exercises: in groups
It's not required, but it will help. Revisit the text editor app you studied last week, this time refactoring the server from a single file to the same folder structure as the exercises. The code in this repo works! Your job is to make sure it still works after you've refactored it :)
- the
courses-web-app
template repo (Group Project)
Again with the refactors?! This week's project is refactor the API from Build RESTful APIs with Node and Express into a full web app. To help you get started, you can use the courses-web-app
template repo.
Besides refactoring the backend into multiple files, you are also expected to develope a frontend for your API in the /client
directory. You can design the frontend however you like, and organize the code in a way that makes sense to you. The main objective this week is to understand how the frontend & backend are related.
- [ ] [repo](https://github.com/_/_) (with a complete README)
- [ ] [live demo](https://_.github.io/_)
- Project Planning
- [ ] [Backlog](https://github.com/_/_/tree/master/project-planning/backlog.md)
- [ ] [Development Strategy](https://github.com/_/_/tree/master/project-planning/development-strategy.md)
- [ ] [Project board](https://github.com/_/_/projects/_)
- Implementation
- [ ] Config
- [ ] Deployed - [deployment url]()
- [ ] data in a .json file
- JSON Schemas
- Schema Validation
- Adding a
schema.json
file to your projects
expand/collapse
- slides
- videos: Part 1, Part 2
- Examples: 12-data-validation
- JSON Schemas
- JSON Schema Validation
- jsonschemavalidator.net (used in the prep videos)
- tv4 validation library (prep video and your projects)
Practice using JSON Schemas & tv4
to protect data saved in a .json file.
- all together: Class Slides
- in groups: 12-data-validation/exercises/1-write-data
- in groups: 2-write-data & 3-write-handlers
It's not required, but it will help. Build a simple virtual file system using a .json data file and schema. This API is very similar to the one you studied the last two weeks, but instead of reading and writing actual files it stores file names and text contents as entries in a single .json file.
impress yourselves! (Group Project)
This week's project is open-ended. Starting with the tv4-validation-fs-template, build a project to impress yourself. You've been at HYF for a few months now and every week your projects have been given to you. You've hopefully learned about planning the steps of your projects, organizing your code, and writing clean code. It's time to put yourself to the test.
Here are some tips to help you find your way:
- start with your user Begin by identifying the type of person who will want ot use your app, and why they would want to use it. Who is this project for? What does the app do for them? Why is this helpful?
- define your data Before you start coding, understand the data your application will be using. This includes writing the schema and creating some starter data by hand.
- write your backend first After defining your data, write an API that allows users to create, read, update, and delete entries in your data file(s).
- [ ] [repo](https://github.com/_/_) (with a complete README)
- [ ] [live demo](https://_.github.io/_)
- Project Planning
- [ ] [Backlog](https://github.com/_/_/tree/master/project-planning/backlog.md)
- [ ] [Development Strategy](https://github.com/_/_/tree/master/project-planning/development-strategy.md)
- [ ] [Project board](https://github.com/_/_/projects/_)
- Implementation
- [ ] Deployed - [deployment link]()
- [ ] A working frontend in the `/client` directory
- [ ] A working API in the `/api` directory
- [ ] A schema and valid data in the `/data` directory
- Students: Here you can find recordings of this module from past classes. Enjoy!
- Coaches: When sending your PR's with links please ...
- Indicate which class you were teaching
- Which week it was (if the module is more than 1 week)
- Give your name
- and a helpful description
Class 7-8
- week 1:
- Part 1: Node, Web Apps, CLI's,
fs
,process.argv
,assert
- Part 2: Exercise recap, Project intro
- Wrap-up: Homework explanation
- Part 1: Node, Web Apps, CLI's,
- week 2:
- week 3:
- week 4
Class 9-10
- Week 1
- Week 2
- Week 3
- Week 4: