This commit is contained in:
John Doe 2020-05-05 03:37:43 +03:00
Родитель 68b57502f9
Коммит 895aa622bf
1 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,39 @@
const express = require('express')
var bodyParser = require('body-parser');
const app = express()
app.use(bodyParser.urlencoded({ extended: true }));
//Dependent of Templating engine
var jade = require('pug');
const port = 5061
function getHTML(input) {
var template = `
doctype
html
head
title= 'Hello world'
body
form(action='/' method='post')
label(for='name') Name:
input#name.form-control(type='text', placeholder='' name='name')
button.btn.btn-primary(type='submit') Submit
p Hello #{username}`
var fn = jade.compile(template);
var html = fn({username: input});
console.log(html);
return html;
}
app.post('/', (request, response) => {
var input = request.param('name', "")
var html = getHTML(input)
response.send(html);
})
app.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`server is listening on ${port}`)
})