-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (33 loc) · 929 Bytes
/
Copy pathindex.js
File metadata and controls
41 lines (33 loc) · 929 Bytes
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
import express from "express";
import bodyParser from "body-parser";
const app = express();
const port = 3000;
const postArray = []
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
// getting request from my server to render each page
app.get("/", (req,res) => {
res.render("index.ejs",{postArray: postArray})
})
app.get("/about", (req,res) => {
res.render("about.ejs")
})
app.get("/contact", (req,res) => {
res.render("contact.ejs")
})
app.get("/idea", (req,res) => {
res.render("mainIdeaBehindThisBlog.ejs")
})
app.get("/post", (req,res) => {
res.render("post.ejs")
})
// rendering a post on my server and also store using an array
app.post("/submit",(req, res) => {
const {title, content} = req.body;
postArray.push({title, content})
console.log(postArray)
res.redirect("/")
})
app.listen(port, () => {
console.log('server started')
});