node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


nodejs module to make POST file uploads

Module allows to send POST requests with Content-type: multipart/form-data with files and any readable streams.


npm install multiparter


  • var request = new multiparter.request(protocol, options)

    Create request object. For protocol you may pass http or https module, options is request options object just like for http.request.

  • request.setParam(field, value)

    Set plain field value for your request.

  • request.addStream(field, fileName, mimeType, streamLength, stream)

    Add stream to request and assign it to specified field. Stream must have mime type (pass application/octet-stream if unsure) and length to calculate request length without loading whole stream data into memory.

  • request.send(callback)

    Send request and receive error as first argument of callback and response as second (usual http.ClientResponse or https.ClientResponse object)


var fs          = require("fs");
var http        = require("http");
var multiparter = require("multiparter");
// test host, but it works 
var request = new multiparter.request(http, {
    host: "",
    port: 80,
    path: "/test2.php",
    method: "POST"
// add some plain params here 
request.setParam("here", "we are");
request.setParam("again", "ok bye!");
// add files you need with readable stream 
// don't forget to crete file test.txt 
// send request and receive response 
request.send(function(error, response) {
    if (error) {
    var data = "";
    response.on("data", function(chunk) {
        data += chunk;
    response.on("end", function() {
        console.log("Data: " + data);
    response.on("error", function(error) {