1
5
Node v24.1.0 (nodejs.org)
submitted 1 week ago by [email protected] to c/[email protected]
2
4
Node v24.0.1 (nodejs.org)
submitted 2 weeks ago* (last edited 2 weeks ago) by [email protected] to c/[email protected]
3
1
submitted 2 weeks ago by [email protected] to c/[email protected]
4
7
submitted 3 weeks ago by [email protected] to c/[email protected]
5
3
submitted 1 month ago by [email protected] to c/[email protected]
6
3
submitted 1 month ago by [email protected] to c/[email protected]
7
5
submitted 1 month ago by [email protected] to c/[email protected]
8
2
submitted 1 month ago by [email protected] to c/[email protected]
9
5
submitted 1 month ago by [email protected] to c/[email protected]
10
0
submitted 3 months ago by [email protected] to c/[email protected]
11
1
submitted 7 months ago by [email protected] to c/[email protected]
12
2
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/[email protected]

When I submit the form twice, three times, etc. I get duplicated form field data. Here is the console output of the form data after every submissions.

Also all the field values are always an array, even if the input field for that value is a text input field? Not sure if this is another issue or not.

Here is my code. Only one JS file and one HTML file...

import fs from 'fs';
import http from 'http';

import { formidable as formidablePackage } from 'formidable';

const port = 8080;

//Will create horizontal line that will fit the width of the terminal window
const horizontalLine = '='.repeat(process.stdout.columns);

const formidable = formidablePackage({
	allowEmptyFiles: true,
	minFileSize: 0,
});

http
	.createServer(async (request, response) => {
		if (request.method === 'POST') {
			let [formFieldData, formFileData] = await formidable.parse(request);

			console.log(formFieldData);
		}

		response.setHeader('Content-Type', 'text/html');

		fs.createReadStream('form.html').pipe(response);
	})
	.listen(port);
<form method="post" enctype="multipart/form-data">
	<input name="myText" />
	<br />
	<input type="checkbox" name="myCheckboxGroupA" />
	<input type="checkbox" name="myCheckboxGroupA" />
	<input type="checkbox" name="myCheckboxGroupA" />
	<br />
	<input type="file" name="myFileA" />
	<br />
	<input type="file" name="myFileB" multiple />
	<br />
	<input type="file" name="myFileC" multiple directory webkitdirectory />
	<br />
	<input type="submit" />
</form>

These are the console logs

$ node form.js
{ myText: [ 'hello world' ], myCheckboxGroupA: [ 'on' ] }
{
  myText: [ 'hello world', 'hello world' ],
  myCheckboxGroupA: [ 'on', 'on' ]
}
{
  myText: [ 'hello world', 'hello world', 'hello world' ],
  myCheckboxGroupA: [ 'on', 'on', 'on' ]
}
{
  myText: [ 'hello world', 'hello world', 'hello world', 'hello world' ],
  myCheckboxGroupA: [ 'on', 'on', 'on', 'on' ]
}

These are the console logs I expected

$ node form.js
{ myText:  'hello world' , myCheckboxGroupA: [ 'on' ] }
{ myText:  'hello world' , myCheckboxGroupA: [ 'on' ] }
{ myText:  'hello world' , myCheckboxGroupA: [ 'on' ] }
{ myText:  'hello world' , myCheckboxGroupA: [ 'on' ] }
13
7
submitted 8 months ago by [email protected] to c/[email protected]
14
5
submitted 8 months ago by [email protected] to c/[email protected]
15
5
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/[email protected]
16
6
submitted 9 months ago by [email protected] to c/[email protected]
17
4
Node v20.16.0 (nodejs.org)
submitted 10 months ago by [email protected] to c/[email protected]
18
13
submitted 10 months ago by [email protected] to c/[email protected]
19
7
submitted 10 months ago by [email protected] to c/[email protected]
20
8
submitted 10 months ago by [email protected] to c/[email protected]
21
9
submitted 10 months ago by [email protected] to c/[email protected]
22
7
submitted 11 months ago by [email protected] to c/[email protected]
23
7
submitted 1 year ago by [email protected] to c/[email protected]
24
6
submitted 1 year ago by [email protected] to c/[email protected]
25
8
submitted 1 year ago by [email protected] to c/[email protected]
view more: next ›

Node.js

272 readers
4 users here now

founded 2 years ago
MODERATORS