Skip to content

Instantly share code, notes, and snippets.

@cklanac
cklanac / nyc-restaurants-data-backup.sql
Created January 2, 2018 17:55
Slim Restaurants DB for ElephantSQL
--
-- PostgreSQL database dump
--
DROP TABLE IF EXISTS grades;
DROP TABLE IF EXISTS restaurants;
DROP TYPE IF EXISTS borough_options;
--
@cklanac
cklanac / challenge-01-node-and-express.md
Last active July 20, 2025 07:50
Challenge 01: Node Express Basics

For this challenge, you'll clone the starter repo, install express, setup a static server and create 2 endpoints to serve Notes. The starter repo contains a simple in-memory database with sample data and a client application to demonstrate the API.

Requirements

  • Clone and setup the starter repo
  • Install express and setup a start command
  • Implement an Express static server
  • Create 2 GET endpoints:
    • GET notes returns a list of notes. If a search term is provided it returns a filtered list, otherwise it returns a full list of notes.
    • GET a note by ID returns a specific note based on the ID provided.
@cklanac
cklanac / simDB-promisified.js
Last active April 19, 2018 16:45
Simple In-Memory Database
'use strict';
// Simple In-Memory Database (async-callback version)
const DELAY = 100;
const { promisify } = require('util');
const simDB = {
// Synchronous Initialize
initialize: function (data) {
@cklanac
cklanac / challenge-02-middleware-and-modules.md
Last active October 12, 2019 01:44
Challenge 02: Express Middleware

For this challenge, you'll create a config module and add 3 pieces of middleware: a logger, a custom 404 handler and a custom 500 error handler.

Then you'll update the client to take advantage of the PUT endpoint by completling the event listener and adding new AJAX call to allow users to update notes.

Requirements

  • Create a config.js module which exports PORT
  • Create a logger middleware which logs all requests to the server
  • Add a custom 404 Handler middleware after the normal routes
  • Add a custom Error Handler middleware as the last piece of middleware (just before app.listen)
@cklanac
cklanac / challenge-03-restful-and-routers.md
Last active July 20, 2025 07:50
Challenge 03: RESTful and Express Routers

For this challenge, you'll add the save and delete features. And, you'll move the endpoints into a router.

Requirements

  • Swap out the custom logger with Morgan
  • Move endpoints to an Express Router
  • Implement save a new Note feature
  • Implement delete a Note feature

Before getting started, remember to create a development branch git checkout -b feature/restful-routers to hold your work.

@cklanac
cklanac / challenge-04-promises.md
Last active July 20, 2025 07:50
Challenge 04: Promises

For this challenge, you'll update both the client and the server to use promises.

On the client, you will change the API methods to return promises instead accepting callbacks. Then update the api.METHOD() calls to use promises.

On the server, you will update simDb to use promises, we'll provide the code. Then update the queries to use promises instead of callbacks.

Requirements

  • Update the server-side code
  • Update the simDb.js file with "promisified" version
@cklanac
cklanac / challenge-mocha-chai-travis.md
Last active July 20, 2025 07:49
Challenge 05: Testing with Mocha Chai

For this challenge you will create a full suite of tests that confirm your app is working correctly. Then you'll setup Continuous Integration to ensure your app continues to work.

Requirements

  • Install mocha, chai and chai-http
  • Update server.js to support tests
  • Create a suite of tests:
    • Test that the environment
    • Test the static server
  • Test the endpoints
@cklanac
cklanac / noteful-app.sql
Last active October 15, 2018 21:01
SQL Scripts to create and populate tables for Noteful App
DROP TABLE IF EXISTS notes;
CREATE TABLE notes (
id serial PRIMARY KEY,
title text NOT NULL,
content text,
created timestamp DEFAULT now()
);
@cklanac
cklanac / challenge-06-sql.md
Last active November 3, 2018 08:47
Challenge 06: SQL Scripts

Noteful Challenge - SQL Database

For this challenge you will create a Postgres database for the Noteful App. You'll write a SQL script that you can use to create and seed a database a database

Requirements

  • Create a noteful-app database
  • Create a SQL (.sql) file that creates a notes tables and inserts sample data
  • Create sample queries
@cklanac
cklanac / knexjs.joins.md
Created February 6, 2018 10:50
Knex.js Joins

Adding Knex to the endpoints

Now that you have a good understanding of the Knex's capabilities, let's look at adding Knex to our Express app endpoints. Quit the nodemon drills.js process and start the server.

Open Postman and navigate to http://localhost:8080/restaurants. You should get back a list of restaurants. The SELECT statement is straight forward, the only thing to point out is the addition of in the `.then(results => res.json(results) );

Inner Join

Let's tackle the grade first.