Created
April 4, 2018 02:40
-
-
Save nasser/112593601763a7edff8b5e229d41c595 to your computer and use it in GitHub Desktop.
remember the index.html goes into a folder called 'public'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Express Demo</title> | |
</head> | |
<body> | |
Served by <em>Express™</em> | |
<img src="hacker.jpg" width=100> | |
<!-- <a href="some-page">Go to some page!</a> --> | |
<form method="post" action="/contact"> | |
<input type="text" name="name"> | |
<input type="text" name="email"> | |
<input type="submit" name="Send"> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() // make a new app | |
app.use(express.static('public')) | |
const bodyParser = require('body-parser'); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
var database = []; | |
app.post('/contact', (req, res) => { | |
var newContact = req.body; | |
database.push(newContact.name); | |
res.send("Current Contacts:" + database.join("\n")); | |
}); | |
// app.get('/', (req, res) => { | |
// res.sendFile("/Users/nasser/Projects/ls-express/index.html"); | |
// }); | |
app.get('/some-page', (req, res) => { | |
res.send("welcome to some page") | |
}); | |
app.get('/req-test', (req, res) => { | |
console.log(req); | |
res.send("done"); | |
}); | |
// app.get('/', function(req/*uest*/, response) { | |
// res.send('Hello World!'); | |
// }); | |
app.listen(3000, () => console.log('Example app listening on port 3000!')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment