0

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)

Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
user2985956
  • 1
  • 1
  • 1
  • Is there anything you already have tried? – node_modules Feb 15 '17 at 09:29
  • 2
    Submit your html form to an API which receives form data and stores in txt file. This is what we can tell when you just post a question. Post your code so that anyone can edit. – Karthik Feb 15 '17 at 09:32

2 Answers2

0

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.

Community
  • 1
  • 1
r.a.m-
  • 499
  • 5
  • 12
0

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!

David R
  • 14,711
  • 7
  • 54
  • 72