Created
December 17, 2015 13:44
-
-
Save mpfund/ee7d4224c94ddf3e5bab to your computer and use it in GitHub Desktop.
nodejs form with express + bodyparser
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
/// <reference path="node.d.ts" /> | |
/// <reference path="express.d.ts" /> | |
// install | |
// npm install express --save | |
// npm install body-parser | |
import express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
app.use(bodyParser.urlencoded({ extended: false })) | |
// parse application/json | |
app.use(bodyParser.json()); | |
app.get('/', function (req, res) { | |
res.send('<form method="post" action="/"><input type="text" name="hallo"></form>'); | |
}); | |
app.post('/', function (req, res) { | |
console.log(req.body); | |
res.send('ok') | |
}); | |
var server = app.listen(3000, function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('Example app listening at http://%s:%s', host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment