I'm getting started with nodejs and express to build a pretty simple app.
So far I'm running a webserver and added an app.get route for my index.html that displays two forms and a submit button.
I'd like to be able to type a string in both forms, click on the submit button and than use both strings on my server (to call a function using those two strings from the forms).
server:
var express = require('express');
var app = express();
//body-parser -> not sure if thats the right approach...
var bodyParser = require('body-parser');
app.use(bodyParser.json());
/* servers main page */
app.get("/", function(req, res) {
res.sendFile(__dirname + '/index.html');
});
//POST route
app.post('/', function(req, res) {
//goal: user types string in both forms, clicks submit, values are being
//received from server to call a function using those strings
});
var port = process.env.PORT || 1337;
app.listen(port, function() {
console.log("Listening on " + port);
});
HTML:
<form action="" method="POST">
Subject:<br>
<input type="text" name="subject" value="default"><br>
Message:<br>
<input type="text" name="message" value="default"><br><br>
<input type="submit" name="submit" value="Submit">
</form>