Skip to content

Commit 742c30f

Browse files
feat: david CD clone with web sever using express and node, including contact form page (#619)
* feat: adds web sever to CD clone with a contact form page using express and nodesjs * chore: move hero and logo images into the right directory * chore: update npm start script * chore: remove empty file * fix: handling data submission * fIX: contact-us server to grab the correct form parameters * chore: delete empty document --------- Co-authored-by: Vicente Vigueras <[email protected]>
1 parent d7630aa commit 742c30f

File tree

10 files changed

+1992
-0
lines changed

10 files changed

+1992
-0
lines changed

lesson_24/davidadenaike/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const express = require("express"); // Get express
2+
const morgan = require("morgan"); // Get morgan
3+
const path = require("path"); // Get path
4+
var debug = require('debug')('myapp:server'); // Get debug logger
5+
6+
const app = express(); // Create express app
7+
8+
app.use(morgan("dev")); // Setup morgan middleware
9+
app.use(express.static(path.join(__dirname, "public"))); // Setup static files
10+
app.use(express.urlencoded({ extended: true })); // Setup urlencoded middleware
11+
app.use(express.json()); // Setup json middleware
12+
app.set("view engine", "ejs"); // Setup view engine
13+
14+
app.get("/", (req, res) => {
15+
console.log("Here")
16+
res.render("contact") // Render index.ejs
17+
})
18+
19+
const contactUsRouter = require("./routes/contact-us"); // Get contact us router
20+
21+
app.use("/contact-us", contactUsRouter); // Setup contact us router
22+
23+
const PORT = process.env.PORT || 3000; // Setup port
24+
25+
// Start the server
26+
app.listen(PORT, () => {
27+
debug(`Server listening on http://localhost:${PORT}`)
28+
})

0 commit comments

Comments
 (0)