Using POST data to write to local file with node.js and express -


i'm trying handle simple post requests , append data local file. however, when try post raw text postman, such 'hi world', what's appended [object object]. i'm not sure causing if nothing should interpreted object on either end. thank you!

var express = require('express'),     fs = require('fs')     url = require('url'); var app = express();  app.configure(function(){   app.use('/public', express.static(__dirname + '/public'));     app.use(express.static(__dirname + '/public'));    app.use(express.bodyparser()); });  app.post('/receive', function(request, respond) {     filepath = __dirname + '/public/data.txt';     fs.appendfile(filepath, request.body, function () {         respond.end();     }); });  app.listen(8080); 

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';     request.on('data', function(data) {         body += data;     });      request.on('end', function (){         fs.appendfile(filepath, body, function() {             respond.end();         });     }); });  app.listen(8080); 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -