Start learning free

LESSON 156 OF 173 · BACKEND: SHIPPING IT

Project: The Release Checklist in JavaScript

Practice

Before a new version goes live, a release checklist makes sure nothing was forgotten on the server. Your function releaseChecklist(env, db, client) gets the server's environment variables as an object, its database, and a test client of its app. It collects what is wrong in an array, problems, and the code at the end prints it.

Each check reads a value, compares it, and pushes a sentence when something is wrong. Here is a check for another setting:

const env = { SHOP_NAME: "Mug Shop", ADMIN_EMAIL: "" };
const problems = [];
if ((env.ADMIN_EMAIL || "") === "") {
  problems.push("set ADMIN_EMAIL");
}
console.log(problems);   // [ 'set ADMIN_EMAIL' ]

Your checklist asks four things, in this order. Development mode is off: NODE_ENV is "production" (a server that doesn't set it counts as "development"). Every name in SECRETS is set and not empty. Every name in MIGRATIONS has its row in the table migrations: .get() gives undefined when it doesn't. And GET /health answers 200.

Six test servers go through the checklist. The finished code prints:

Server 1: all set
Ready to release
Server 2: development mode left on
To do: turn development mode off (NODE_ENV is development)
Server 3: secrets forgotten
To do: set the secret SECRET_KEY
To do: set the secret WEBHOOK_SECRET
Server 4: new code, old database
To do: run the migration 003_add_reviews
Server 5: the app is not healthy
To do: fix /health, it answers 503
Server 6: nothing done yet
To do: turn development mode off (NODE_ENV is development)
To do: set the secret SECRET_KEY
To do: set the secret PAYMENTS_API_KEY
To do: set the secret WEBHOOK_SECRET
To do: run the migration 001_create_products
To do: run the migration 002_create_orders
To do: run the migration 003_add_reviews
To do: fix /health, it answers 503

Your task: inside releaseChecklist, add the four checks: development mode, then the secrets, then the migrations, then /health. Each one pushes the sentence that follows To do: in the output above.


Assignment
Follow the Coding Tutorial to add the four checks of the release checklist: development mode off, secrets set, migrations run and /health green.


Hint
|| gives the value on its right when the one on its left is undefined or empty. Look up each migration with a ? placeholder and pass the name to .get(name). Put await in front of client.get, then read response.status.


STEP 1 OF 10
    Ctrl + Enter to check

    Ship Release Checklist in JavaScript

    Keep going with JavaScript1,600+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free