-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (39 loc) · 1.15 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const adj = require('adjectives');
const express = require('express');
const {nouns, one} = require('nouns');
const a = require('indefinite');
const bodyParser = require("body-parser");
const ejs = require("ejs");
const app = express();
app.use(express.static(__dirname));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
//starting default value
let pageContent = "the moon is..."
app.get("/", function(req, res){
res.render("index",{
pageContent: pageContent
});
});
app.post("/", function(req, res){
pageContent = createContent();
res.redirect("/");
});
app.get("/about", function(req, res){
res.render("about",{});
});
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port, function(){
console.log("Server has started.");
});
function createContent(){
const randmonAdj = adj[Math.floor(Math.random() * adj.length)];
//correct adjective with right grammar
const correctGrammarAdj = a(randmonAdj);
// random nouns
const randomNoun = one();
return "the moon is " + correctGrammarAdj + " " + randomNoun;
}