In this week, we will be learning about server-side programming using JavaScript running in Node.js. We we learn how to run Node scripts and make our own API.
Emphasis this week will be on understanding when it is necessary to use server-side programming, and differentiating between server-side and client-side code.
- Node.js
- What is back end/server side programming?
- What is Node.js? What's the motivation behind its creation?
- How do you install Node.js?
- What are the Node.js core libraries? How do you use them?
- What capabilities does Node have that browser JS does not? What about vice versa?
- npm
- What is
npm
? What is the difference betweennpm
, the command line tool, and "npmjs.com"? - How do you create an npm project? How do you install and keep track of dependencies?
- How do you use "npmjs.org"?
- How do you use
npm
withgit
?
- What is
- APIs
- What is an API?
- What is REST?
- What is CORS?
- Express
- What is a static web server? How do you create one with Express?
- How do you Express to return JSON?
- Why would you use Express to make API requests, rather than making the requests client-side?
- Data Persistence
- What are ways that you can persist data?
- Can you persist data without a database? When do you need to use a database?
- What is the "back-end" / server-side programming?
- What is a server side programming language? How does it differ from client-side programming in the browser?
- What is Node.js? How does it relate to Express.js?
- What is npm, what is a
package.json
, how they are related, and why they are important - How to install node.js dependencies using npm.
- What does it mean to serve static files using a web server?
- Can you clearly delineate between your server-side code and your client-side code? Explain how they are different.
- What is an API?
- What is REST?
- What is CRUD?
- How do we persist data? Can we persist data on a server without a database?
- What is the difference between server-side code and the server machine? How is this related to a platform-as-a-service (PaaS)?
- How do you use dynamic data in your website?
- Can you explain the difference between a server (code), server (machine), and server (the service)?
This week we will be focusing our attention on server-side programming, otherwise known as the "back-end" of web applications.
In this class we will be:
- Learning to program a server with Node.js
- Writing server-side JavaScript to create our own REST APIs that allow us to communicate between our client and server to perform CRUD operations.
Students will walk away with a deeper understanding of:
- The terminal / command-line
- NPM, Node.js and Express.js
- REST API structure
TBD
Topics we are not covering, but are of importance:
- TypeScript
- Dependency management, transpiling and bundling (Webpack, Parcel, Rollup, Browserify, Babel)
- Node
- In a nutshell:
- same language, different capabilities
- you could use any language (Python, Ruby, C++) on your computer, but it's nice using the same language for a whole project
- Doesn't have:
window
, nodocument
, noDOM
, nocanvas
(therefore no p5.js!)
- Does have:
- Access to the computer's file system
- (Potentially) faster computation
- Can be used in non-web contexts, for example, to crunch data
- In a nutshell:
- Browser
- In a nutshell:
- Only JavaScript runs in a browser, so you don't have other options
- Always used in conjunction with an HTML document
- Doesn't have:
- file system (your computer's files) access
import
orrequire
- In a nutshell:
- Does have
- access to
window
,document
- access to browser API's, like Web Audio and Canvas
- access to
- Starting the Node REPL (Read-eval-print loop). This is the same as opening the Developer Console in a browser.
-
$ node
-
- Running a script - code runs from top to bottom.
-
$ node script.js
-
- how to debug? ==> lots of console.log() :)
require()
vs.import
- there are 2 ways to import packages but depends on the version of Node.js you're using. For usage of
import
please use Node.js version >=12.
- there are 2 ways to import packages but depends on the version of Node.js you're using. For usage of
- Core Node libraries
fs
path
http
- Initializing a Node project - using
npm init
- Installing dependencies and saving them to your
package.json
- Why use express on top of Node? To create a web server
- you can technically create one using just the
http
module, but it's a lot of code.- TODO: example code
- Here's some examples of other web server code:
- you can technically create one using just the
- Serving different HTML files based on a route
- getting the correct path w/
path.resolve(__dirname, 'views') + 'about.html'
- convention:
views
directory
- getting the correct path w/
- Middleware
- API that we are building towards: Todo App? Tarot or Astrology related?
- How to build APIs with express:
app.get
app.post
app.put
app.delete
requests
andresponse
==> (res, req)- Dynamic routes
- url params
- query params
- Storing/updating json object on the server
- Writing files to the server
- maybe for later: node-fetch/isomorphic fetch or external API requests from the server
- Quick intro to cURL
- Introduction to Postman
- using
fetch
to grab data - render to front end using template strings
These are topics that won't be covered in the class at all, or will be covered in a later week.
Topics we are not covering, but are of importance:
- ...
- ...
- ...
- Break down of the class schedule example:
- :15 Overview, context, examples and vocabulary
- :20 Instruction & hands on exercise
- :15 Wrap-up discussion & sharing, reflection or journal and next steps
- Laptop & Power charger
- Text Editor (VS Code)
- Web browser (chrome or firefox preferred, but safari is ok)
- Node.js installed (with NVM?)
- Terminal/command-line
What materials (readings, tasks, exercises) should students complete before class to be prepared for the lesson.
TBD
- term:
- route:
- ...
- route:
Descriptions of each exercise or phase of class. Similar to pacing but with more description of steps.
Include any sources cited, but not directly linked in the unit.