Node.js

254 readers
1 users here now

founded 2 years ago
MODERATORS
1
2
3
4
5
5
submitted 5 months ago by lysdexic to c/nodejs
6
 
 

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' ] }
7
8
9
6
submitted 7 months ago* (last edited 7 months ago) by lysdexic to c/nodejs
10
11
4
Node v20.16.0 (nodejs.org)
submitted 8 months ago by mac to c/nodejs
12
13
7
submitted 8 months ago by mac to c/nodejs
14
8
submitted 8 months ago by mac to c/nodejs
15
9
submitted 9 months ago by mac to c/nodejs
16
7
submitted 9 months ago by mac to c/nodejs
17
7
submitted 11 months ago by mac to c/nodejs
18
6
submitted 11 months ago by mac to c/nodejs
19
20
5
submitted 1 year ago by lysdexic to c/nodejs
21
5
submitted 1 year ago* (last edited 1 year ago) by mac to c/nodejs
 
 

The Node.js project will release new versions of the 18.x, 20.x, 21.x releases lines on or shortly after, Tuesday, April 9, 2024 in order to address:

  • 1 high severity issues.
  • 1 medium severity issues.
22
6
submitted 1 year ago* (last edited 1 year ago) by mac to c/nodejs
 
 

Linked in the post is 21.7.2

23
8
submitted 1 year ago* (last edited 1 year ago) by mac to c/nodejs
 
 

The Node.js project will release new versions of the 18.x, 20.x, 21.x releases lines on or shortly after, Wednesday, April 3, 2024 in order to address:

  • 1 medium severity issue.
  • 1 high severity issue.
24
25
6
require(esm) in Node.js (joyeecheung.github.io)
submitted 1 year ago by lysdexic to c/nodejs
view more: next ›