azat-co / expressworks

Learn Express.js from the author of one of the best books on Express.js—Pro Express.js— with this workshop that will teach you basics of Express.js.
MIT License
709 stars 220 forks source link

GOOD OLD FORM problem: socket hang up #79

Closed AltynDaur closed 8 years ago

AltynDaur commented 9 years ago

Here my code: var express = require('express'),bodyparser = require('body-parser'); var app = express(); app.use(bodyparser.urlencoded({extended: false})); app.post('/form',function(req,res){ req.body.str.split('').reverse().join(''); }); app.listen(process.argv[2]);

When I tried verify this code, I've got this: events.js:85 throw er; // Unhandled 'error' event ^ Error: socket hang up at createHangUpError (_http_client.js:215:15) at Socket.socketOnEnd (_http_client.js:300:23) at Socket.emit (events.js:129:20) at _stream_readable.js:908:16 at process._tickCallback (node.js:355:11)

ankitverma2211 commented 8 years ago

hey there ,

I was stuck at the same place as you . The solution is to put the

req.body.str.split('').reverse().join('');

inside

res.end(req.body.str.split('').reverse().join('') );

I will post my code below hope that helps

var express = require('express') var bodyparser = require('body-parser') var app = express() app.use(bodyparser.urlencoded({extended:false})) app.post('/form',function(req,res){

    res.end(req.body.str.split('').reverse().join('') );

})

app.listen(process.argv[2]);

AltynDaur commented 8 years ago

Thank you so much! It was little dumb mistake))

ankitverma2211 commented 8 years ago

Glad I was able to help you :)