Skip to content

Instantly share code, notes, and snippets.

@mpfund
Created December 17, 2015 13:44
Show Gist options
  • Save mpfund/ee7d4224c94ddf3e5bab to your computer and use it in GitHub Desktop.
Save mpfund/ee7d4224c94ddf3e5bab to your computer and use it in GitHub Desktop.
nodejs form with express + bodyparser
/// <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