I have the following code
<!--index.html-->
<form id = "lang" action="/myform" method="POST" >
<input type="text" name="mytext" required />
<input type="submit" value="Submit" />
</form>
and
//index.js
var fileServer = new(nodeStatic.Server)();
var app = http.createServer( function(req, res){
fileServer.serve(req, res);
}).listen(port);
var io = socketIO.listen(app);
io.sockets.on('connection', function(socket) {
console.log('recieved connection ');
// convenience function to log server messages on the client
How do I send data in the textbox with id "lang" over to index.js and store it in some variable?
using express by placing it as a parameter in http.createServer()
and executing filsServer.serve(req, res)
in a callback:
express = require('express');
app2 = express();
http = require('http');
app2.post('/myform', function(req, res){
console.log(req.body.mytext);
});
var app = http.createServer(app2, function(req, res){
fileServer.serve(req, res);
}).listen(8082);
this obviously wouldn't work because I need the index.html page to load to fill in the form to begin with and by executing the code above, the program is expecting some form data even before the html page can load.
Is there another way I can send the data?
I got it to work. Here's the code:
Despite having created a server using express, I still needed to create the server using the HTTP module because an express server doesn't work with the socket.io module.
And I had used the express server to take care of my static files.