4

I am currently trying to pass a simple text file from Postman onto a Node.js server in order to save the text file into a folder.
I have replicated the code found on this post: Using POST data to write to local file with node.js and express, however, I keep running into the same error shown here which states "Cannot POST /recieve".

POSTMAN SETUP

The code I am running is from the post earlier and is:

var express = require('express'),

    fs = require('fs')

    url = require('url');

var app = express();

app.use('/public',  express.static(__dirname + '/public'));

app.use(express.static(__dirname + '/public'));

app.post('/receive', function(request, respond) {

    var body = '';

    filePath = __dirname + '/public/data.txt';
    respond.write(__dirname);
    request.on('data', function(data) {

        body += data;

    });

    request.on('end', function (){

        fs.appendFile(filePath, body, function() {

            respond.end();

        });

    });

});

app.listen(8080);

I then run node server.js in terminal then I POST http://localhost:8080/recieve with a body of a binary file which just contains some numbers.

Someone else was able to get the code working and able to transfer a file with it, however, I cannot find the discrepancy between our programs or methods.

Here is the folder that everything is contained in for reference. Inside public is data.txt which is the file I am trying to append to.

Folder Setup

Any ideas on what I am doing wrong?

  • Use a buffer: https://stackoverflow.com/questions/16598973/uploading-binary-file-on-node-js ; Also response.send("Message") is much understandable. – Shihab Jul 02 '18 at 06:28
  • Also, for sending file: https://stackoverflow.com/questions/19818918/nodejs-sending-uploading-a-local-file-to-a-remote-server – Shihab Jul 02 '18 at 06:32

1 Answers1

1

You spelled receive incorrectly.

General Grievance
  • 4,555
  • 31
  • 31
  • 45