DavidRT49 DavidRT49 - 2 years ago 79
Node.js Question

nodeJS save post request of inputboxes in a file

var input = '';
for (i = 0; i < array.length; i++)
input += <input name=line_"+i+ " type=text >"+"\n";

This cycle create HTML input boxes depending on the length of an array
and saves these in the string "input".
For each of them I assign the name
and the number of index
for example the name of first will be
, the second

if (req.url=='/postContent'){

var body='';
req.on('data', function (data) {
body += data;
req.on('end',function () {

var post = qs.parse(body);

for (i = 0; i < array.length; i++) {
fs.appendFile(databaseFile, "line"+i+": "+post.line_+"["+i+"]"+"\n");
res.writeHead(302, {
'Location': '/'

Now when there is a post request in one of the input boxes I want to save this in a file. I try to write
but the program does not find the name of input boxes in fact the result is this:

riga0: undefined[0]

How can I do to write
"i" in the sense of variable.

Answer Source

Did you try this?

post['line_' + i]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download