Import of glitchdotcom/hello-express

This commit is contained in:
Glitch (hello-express) committed 2020-02-19 22:18:49 +00:00
1 parent ca6674f38e
commit e78428c94d
7 files changed
+130 -138

No files matched your search

+19 -7
View File
@@ -1,22 +1,34 @@
// server.js
// where your node app starts
// init project
// we've started you off with Express (https://expressjs.com/)
// but feel free to use whatever libraries or frameworks you'd like through `package.json`.
const express = require("express");
const app = express();
// we've started you off with Express,
// but feel free to use whatever libs or frameworks you'd like through `package.json`.
// our default array of dreams
const dreams = [
"Find and count some sheep",
"Climb a really tall mountain",
"Wash the dishes"
];
// http://expressjs.com/en/starter/static-files.html
// make all the files in 'public' available
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));
// http://expressjs.com/en/starter/basic-routing.html
app.get("/", function(request, response) {
// https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
response.sendFile(__dirname + "/views/index.html");
});
// send the default array of dreams to the webpage
app.get("/dreams", (request, response) => {
// express helps us take JS objects and send them as JSON
response.json(dreams);
});
// listen for requests :)
const listener = app.listen(process.env.PORT, function() {
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});