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".
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.
Any ideas on what I am doing wrong?