Created
November 26, 2019 11:55
-
-
Save myogeshchavan97/0df061fb08521a7df18dc0ca65eed453 to your computer and use it in GitHub Desktop.
Index js file
This file contains 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
// section 1 | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
app.use(express.static('public')); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
// section 2 | |
app.get('/', (req, res) => { | |
res.send("<h1>Welcome to the world of Express!</h1>"); | |
}); | |
const users = [{ | |
firstName: 'David', | |
lastName: 'Jonhnson', | |
email: 'david@gmail.com' | |
}, { | |
firstName: 'Renn', | |
lastName: 'Mead', | |
email: 'renn@gmail.com' | |
}]; | |
app.get('/users', (req, res) => { | |
res.send(users); | |
}); | |
app.post('/users', (req, res) => { | |
users.push(req.body); | |
res.send(users); | |
}); | |
// section 3 | |
app.listen(3000, (req, res) => { | |
console.log('server started on port 3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment