1
2
submitted 3 weeks ago* (last edited 3 weeks ago) by trymeout@lemmy.world to c/nodejs@programming.dev

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' ] }
2
7
3
5
submitted 1 month ago by neme@lemm.ee to c/nodejs@programming.dev
4
5
submitted 1 month ago* (last edited 1 month ago) by lysdexic@programming.dev to c/nodejs@programming.dev
5
6
submitted 2 months ago by hongminhee@lemmy.ml to c/nodejs@programming.dev
6
4
Node v20.16.0 (nodejs.org)
submitted 3 months ago by mac@programming.dev to c/nodejs@programming.dev
7
13
submitted 3 months ago by mac@programming.dev to c/nodejs@programming.dev
8
7
submitted 3 months ago by mac@programming.dev to c/nodejs@programming.dev
9
8
submitted 3 months ago by mac@programming.dev to c/nodejs@programming.dev
10
9
submitted 3 months ago by mac@programming.dev to c/nodejs@programming.dev
11
7
submitted 4 months ago by mac@programming.dev to c/nodejs@programming.dev
12
7
submitted 5 months ago by mac@programming.dev to c/nodejs@programming.dev
13
6
submitted 5 months ago by mac@programming.dev to c/nodejs@programming.dev
14
8
15
5
16
5
submitted 6 months ago* (last edited 6 months ago) by mac@programming.dev to c/nodejs@programming.dev

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.
17
6
submitted 6 months ago* (last edited 6 months ago) by mac@programming.dev to c/nodejs@programming.dev

Linked in the post is 21.7.2

18
8
submitted 7 months ago* (last edited 7 months ago) by mac@programming.dev to c/nodejs@programming.dev

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.
19
8
20
6
require(esm) in Node.js (joyeecheung.github.io)
21
3

cross-posted from: https://programming.dev/post/11927506

Many times when I’ve tried to write some code in Node.js using ES modules I’ve found myself reaching for __dirname and then looking up how to replace it. Now Node.js, Deno and Bun support import.meta.dirname. Check out the article for more detail.

22
9
submitted 7 months ago by mac@programming.dev to c/nodejs@programming.dev
23
12
24
11
25
4
view more: next ›

Node.js

216 readers
4 users here now

founded 1 year ago
MODERATORS