-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
31 lines (26 loc) · 956 Bytes
/
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
const express = require('express')
const app = express()
var bodyParser= require('body-parser');
var fs = require('fs')
//express.static(root, [options])
app.use(bodyParser.urlencoded({extended:true}))
app.set('title', 'DonaDoce')
app.use(express.static('public'))
app.post('/submit', (req,res)=> {
var clienteData = JSON.stringify(req.body);
console.log('Dados do cliente:' + JSON.stringify(req.body))
//res.redirect('/')
res.send('Seu pedido será entregue..' + clienteData)
fs.readFile('data.json', 'utf8', function(){
fs.writeFile('clienteData.json', clienteData, function(){
console.log('Salva dados do cliente: clienteData.json');
})
})
})
app.get('title')
app.get('/', (req, res) => {
res.send('Seu pedido será entregue..')
})
app.listen(process.env.PORT || 3000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});