Hi,
This is the Glitch project
and below is the myApp.js file:
"use strict";
var express = require('express');
var app = express();
// --> 7) Mount the Logger middleware here
app.use((request, response, next) => {
console.log(`${request.method} ${request.path} - ${request.ip}`);
next();
});
// --> 11) Mount the body-parser middleware here
/** 1) Meet the node console. */
console.log("Hello World");
console.log(process.env.PORT);
/** 2) A first working Express Server */
// app.get("/", (request, response) => response.send("Hello Express"));
/** 3) Serve an HTML file */
const absolutePath = __dirname;
app.get("/", (request, response) => response.sendFile(absolutePath + "/views/index.html"));
/** 4) Serve static assets */
app.use("/", express.static(absolutePath + "/public"));
/** 5) serve JSON on a specific route */
/** 6) Use the .env file to configure the app */
app.get("/json", (request, response) => {
let message = "Hello json";
process.env.MESSAGE_STYLE === "uppercase" ? message = message.toUpperCase() : "";
response.json({message: message});
});
/** 7) Root-level Middleware - A logger */
// place it before all the routes !
/** 8) Chaining middleware. A Time server */
app.get("/now", (request, response, next) => {
request.time = new Date().toString();
next();
}, (request, response) => {
response.json({
time: request.time
});
});
/** 9) Get input from client - Route parameters */
app.get("/:word/echo", (request, result) => {
const { word } = request.params;
result.json({
echo: word
});
});
/** 10) Get input from client - Query parameters */
// /name?first=<firstname>&last=<lastname>
app.get("/name", (request, response) => {
const firstName = request.query.first;
const lastName = request.query.last;
response.json({
name: `${firstName} ${lastName}`
});
});
/** 11) Get ready for POST Requests - the `body-parser` */
// place it before all the routes !
/** 12) Get data form POST */
// This would be part of the basic setup of an Express app
// but to allow FCC to run tests, the server is already active
/** app.listen(process.env.PORT || 3000 ); */
//---------- DO NOT EDIT BELOW THIS LINE --------------------
module.exports = app;