Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

410
Views
How to use FormData in node.js without Browser?

I want to make a post request in nodejs without browser since it is backend code.

const formdata = new FormData()
formdata.append('chartfile', file);

But above code gives me error as FormData not defined. I am working with ES6.

Anybody, who can let me know how to use the FormData in nodejs?

over 4 years ago · Santiago Trujillo
5 answers
Answer question

0

You can use form-data - npm module. because formData() isn't NodeJS API

Use it this way,

var FormData = require('form-data');
var fs = require('fs');
 
var form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', new Buffer(10));
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
over 4 years ago · Santiago Trujillo Report

0

FormData is a part of JS web API (not included in native NodeJS). You can install the form-data package instead.

over 4 years ago · Santiago Trujillo Report

0

I would suggest the npm module formdata-node because it's a complete (spec-compliant) FormData implementation for Node.js. It supports both ESM/CJS targets, so EM6 is supported. You can find a few examples at the npm module page.

over 4 years ago · Santiago Trujillo Report

0

No need for an npm module, URLSearchParams does the same exact thing!

Original Example

var fs = require('fs');
 
var form = new URLSearchParams();
form.append('my_field', 'my value');
form.append('my_buffer', new Buffer(10));
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));

Axios Example

const formData = new URLSearchParams();
formData.append('field1', 'value1');
formData.append('field2', 'value2');
const response = await axios.request({
  url: 'https://example.com',
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  data: formData
});
over 4 years ago · Santiago Trujillo Report

0

In my opinion the cleanest solution that requires no additional dependencies is:

const formData = new URLSearchParams({
  param1: 'this',
  param2: 'is',
  param3: 'neat',
}) 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!