2017-02-16 1 views
1

文字列を印刷しようとすると、実行が中断してプログラムが終了します。文字列の印刷中にコードが実行を突然停止する

var config = require('../config.json'); 
var upacConfig = config.upac; 

var endpoint = upacConfig.endpoint; 
var customer = upacConfig.customer; 
var port = upacConfig.port; 

const http = require('http'); 
const util = require('util'); 

module.exports.getAll = function getAll(cb) { 
    var url = "/" + upacConfig.methods.all + "?customer=" + customer; 
    console.log(url); 
    http.request({ 
    host: endpoint, 
    path: url, 
    port: port 
    }, function(resp) { 
    let s = ''; 
    // console.log('response'); 
    // var lines = 0; 
    resp.on('data', function(d){ 
     s += d.toString(); 
     // console.log(++lines); 
    }) 
    .on('end', function(){ 
     console.log(typeof s); 
     console.log('length:', s.length); 
     console.log(s); // <-- problem! lines below are not executed... 
     console.log('length:', s.length); 
     cb(null, s); 
    }) 
    }) 
    .on('error', e => { 
    console.log('Err:', e); 
    }) 
    .end(); 
}; 

ノードのバージョン:7.1.0

次のされたすべてのコードを出力することを:

/api/v1/all?customer=foo 
string 
length: 323416 

編集:MVEについては、次のようにします。ここでは

は簡単ですサーバーは、上記の文字数のテキストファイルを提供します。 (私のJSON文字列は長かったです...)。

const http = require('http'); 
const fs = require('fs'); 
const path = require('path'); 
var file = path.join(__dirname,'json.txt') 

var app = http.createServer(function(req, res) { 
    fs.createReadStream(file).pipe(res); 
}); 

app.listen(3000); 

ここには、aboveが何を提供するかを示すテストクライアントがあります。

const http = require('http'); 

http.request('http://localhost:3000/', r => { 
    var s = ''; 
    r.on('data', d => s+= d) 
    .on('end',() => { 
     console.log('length:', s.length); 
     console.log(s); 
    }); 
}).end(); 
+0

あなたは 'process.stdout.write(s);を試してみることができますか? –

+0

は上記を試しました...同じ結果:( – deostroll

+0

' console.log( 'String:'、s); ' –

答えて

0

私はjson.txt 324418で試してみました、それはあなたがwindbgのを装着しようとすると、コールスタックを共有できるのWindows 10上で私のために働きましたか?

+0

私はwindbgの使い方がわからないので、専用ルームに招待します。 rooms.deackaceflow.com/rooms/135919/deospace – deostroll

関連する問題