I am learning Node.js scripting.
I want to read input-text from textbox in html page with an option submit
, it should save the content to .txt file using node.js (using POST/GET)
I am learning Node.js scripting.
I want to read input-text from textbox in html page with an option submit
, it should save the content to .txt file using node.js (using POST/GET)
your Node.js server should not care about the origin of the data (if it comes from textbox or any other html element).
This answer should give you a clue: https://stackoverflow.com/a/4296402/418947
In the node app.post function you will use file system api Node file api docs to save the data to your .txt file.
Assuming that your templating engine is ejs
,
Your View page (which consists the textbox) would look like,
extends layout
block content
h1= title
form(name="frmTest", method="get" action="/myform")
div.input
input(type="text", name="mytext")
div.actions
input(type="submit", value="add")
And in the router you can get the textbox value using the query
parameter of the request object like this,
router.get('/myform', function(req, res){
var myText = req.query.mytext;
res.send('Your Text:' +myText);
});
Hope this helps!