https://youtu.be/UPN6D20dcO4

Environment Variables allow us to store and retrieve information such as API Keys and Database Passwords from a system. This means we don't have to expose these in our source code. Node can access these from process.env.

  1. Go .env in glitch and add a new variable with 'MESSAGE_STYLE' as the key and 'uppercase' as the value
  2. Create a route for GET '/json'
  3. In the function, return the JSON with captial letter message if process.env.MESSAGE_STYLE is 'uppercase' , and the normal message otherwise
  4. Comment out the GET '/json' from part 5 to avoid conflict
let message = { message: "Hello json" };
app.get("/json", (request, response) => {
  if (process.env.MESSAGE_STYLE === "uppercase") {
    response.json({ message: "HELLO JSON" });
  } else {
    response.json(message);
  }
});

Concepts

process.env

The process.env property returns an object containing the user environment.

Node.js v14.5.0 Documentation

response.json()

Sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using JSON.stringify(). The parameter can be any JSON type, including object, array, string, Boolean, number, or null, and you can also use it to convert other values to JSON.

4.x API

app.get()

Routes HTTP GET requests to the specified path with the specified callback functions.

5.x API