Node.js answers twice

I have weird behavior with my new installation of node (from git) on a debian machine. It seems that the problem is not in my code, because everything works well on windows. I already know that this is not a favicon problem.

here is what i wrote:

var app = require('express')() , server = require('http').createServer(app) , io = require('socket.io').listen(server) , url = require('url') , qs = require('querystring') , request = require('request') , fs = require('fs') 

followed by

 server.listen(3000); app.post('/postReload', function (req, res) { var fullBody = ''; req.on('data', function(chunk) { fullBody += chunk.toString(); if (fullBody.length > 1e6) { req.connection.destroy(); } }); req.on('end', function() { out = qs.parse(fullBody); vars = out.vars || ''; if(out.module && out.value){ // do the job // console.log here is done twice ! } res.writeHead(200, {'Content-Type': 'text/html'}) res.end(); }); }); 

When writing another way:

 app.post('/postReload', function (req, res) { // console.log here is done twice ! } 

The problem affects every browser, and one week of testing did not solve anything.

Anyone got an idea?

Double action occurs when curling or accessing the browser.

+4
source share
1 answer

Merci Hector Correa.

So I declared socket.io ... my new and simple code:

 var express = require('express') var app = express(); var server = http.createServer(app); var io = require('socket.io').listen(server); app.get('/', function (req, res) { console.log('Only one time !!!') res.end(); }) 

Now I continue coding.

+1
source

Source: https://habr.com/ru/post/1439999/


All Articles