Friday, 12 May 2017

Why control isn't going to app.use?

I have a nodejs server serving static files (a json file, 2 d3 files called scatter.js and rect.js) from /view and code looks like this.

var express = require('express'),
     app = express(),
     serveStatic = require('serve-static');

var match_all = require('./match_all');
match_all();

app.use(serveStatic(__dirname + '/view'));

app.listen(3000,function (){
    console.log("App is listening on port 3000");
});

and match_all looks like this.

var elasticsearch = require('elasticsearch');
var rl =  require('readline');
var fs = require('fs');


var syscall;
module.exports = function(){
var client = new elasticsearch.Client({
     host: '192.168.11.163:9200',
     log: 'trace'
 });

 client.ping({
   requestTimeout: 30000,
  }, function (error) {
 if (error) {
    console.error('elasticsearch cluster is down!');
 } else {
            getmeres(client);
 }
 });


 function getmeres(client,syscall){
    client.search({
   index: 'sys',
   body: {
   size:'10',
   _source: {
       include: ["Ts", "pid", "syscall_name"]
   },
   query: {
      match_all: {}
   }
  }
 },function (error,response) {
if (error) {
     console.trace('Search query failed');
} 
else {
    console.log('All is well');
    d=response;//console.log(response);
    showdocs(d)
}
});
}

 function showdocs(d){
 console.log(d.hits.hits);
 var da = d["hits"]["hits"].map(function(i){
    return i['_source'];
 });
var string_of_da = JSON.stringify(da,null,'\t');
    fs.writeFile("/root/proj/lib/view/libtrace.json",string_of_da,function(err) {
            if(err) {
            return console.log(err);
}

console.log("The file was saved!");
});
}
};

Now if I run match control returns after file was saved! but when I run it from the server file, control doesn't jump to app.use after match_all();

How can I do this?

Any help is appreciated! Thank you.



via Vintux

No comments:

Post a Comment