• Writing, building, and testing Node.js applications
  • Node.js (often shortened to Node) is a JavaScript platform—a way to run JavaScript.
    • node myfile.js
  • MEAN stack is an all-JavaScript web application stack consisting of MongoDB (a database controlled by JavaScript), Express, Angular.js (a front-end JavaScript framework), and Node.js.
  • Express is a relatively small framework that sits on top of Node.js’s web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing; it adds helpful utilities to Node.js’s HTTP objects; it facilitates the rendering of dynamic HTML views; it defines an easily implemented extensibility standard.
  • The core parts of Express
    • Middleware: Rather than one monolithic request handler function, you call several request handler functions that each deal with a small chunk of the work. These smaller request handler functions are called middleware functions, or middleware.
    • Routing: It breaks the one monolithic request handler function into smaller pieces. These request handlers are executed conditionally, depending on what URL and HTTP method a client sends.
    • Subapplications: As your applications get larger, though, you’ll want to break them up into multiple folders and files.
    • Conveniences: A bunch of extra functionalities
  • Express is often used to power single-page applications (SPAs).
  • List of resources:
  • Installing Node
    • https://nodejs.org/download/
    • When you install Node, you actually get two programs: Node (as you might expect) and something called npm (deliberately lowercase). npm is an official helper for Node that helps you with your Node projects.
  • Create new project
    • npm init
  • Install modules
    • npm install xxx --save
  • Asynchronous things are handled by callbacks.
  • “What the heck is the event loop anyway?”
  • At a high level, Express provides four major features
    • Middleware
    • Routing
    • Extensions to request and response objects
    • Views
  • Middleware
    • With middleware, rather than having your request pass through one function you write, it passes through an array of functions you write called a middleware stack.
    • When you start a server, you start at the topmost middleware and work your way to the bottom.
  • Routing
    • Matching fixed routes
    • Routes with parameters
    • Use regular expressions to do even more complex matching
  • Extending request and response
    • Express augments the request and response objects that you’re passed in every request handler.
  • Views
    • A number of different view engines are available. There’s EJS (which stands for Embedded JavaScript), Handlebars, Pug, and more.
    • response.render
    • Bootstrap is a bunch of CSS and JavaScript that provides a lot of default styling. You can absolutely write navbars and buttons and header CSS yourself, but Bootstrap helps you get up and running quickly. You can find out more at http://getbootstrap.com/.
  • Middleware and the middleware stack
    • When next is called, Express will go on to the next function in the stack.
    • Logger: Morgan
    • Static file: express.static
  • Error-handling middleware
    • next(new Error ("Something bad happened!"))
  • Other useful middleware (http://expressjs.com/resources/middleware.html)
  • The features of routing
    • Grab a parameter by putting it in your route with a colon in front of it
    • Using regular expressions to match routes
    • Grabbing query arguments
  • Using routers to split up your app
    • A router is an isolated instance of middleware and routes. Routers can be thought of as “mini” applications only capable of performing middleware and routing. Every express application has a built-in app router.
    • express.Router()
  • Serving static files
    • express.static
    • res.sendFile
  • Using Express with HTTPS
  • Create, read, update, delete APIs
    • GET: gets resources, idempotent
    • POST: create records, not modify existing records, non-idempotent
    • PUT: update or change, idempotent
    • DELETE: delete, idempotent
  • Setting HTTP status codes
    • 1xx: hold on
    • 2xx: here you go
    • 3xx: go away
    • 4xx: you messed up
    • 5xx: I messed up
  • Everything you need to know about EJS
    • You can print the results of JavaScript expressions in two ways: <% expression %> prints the result of the expression; <%- expression %> prints the result of the expression and escapes any HTML entities that might be inside.
    • You can also avoid adding extraneous newlines with <% expression -%>
    • Appending a colon (:) to an output will allow filters to be applied. Filters take the output of an expression and filter it to change the output.
  • Why MongoDB?
    • Relational databases are a lot like spreadsheets. Their data is structured.
    • NoSQL databases are different from relational databases in that they’re generally not structured like a spreadsheet.
    • Although Mongo isn’t written in JavaScript, its native shell uses JavaScript.
    • Mongo: Mongoose
    • SQL: Sequelize
  • Talking to Mongo from Node with Mongoose
    • “bcrypt-nodejs”
    • “mongoose”
  • Testing Express applications
    • [Skip for now]
    • Introducing the Mocha testing framework
    • Testing Express servers with SuperTest
  • Security
    • [Skip for now]
    • Enforcing good JavaScript with JSHint
    • Using HTTPS

Leave a comment