Wednesday, 15 March 2017

Why node js express route never stops running

I have made a route in express and it works below is the code snippet:

In app.js I have added:

var generateOrders      = require('./routes/generateOrders');
app.use('/generate-orders', generateOrders);

In generateOrders.js:

var express = require('express');
var router = express.Router();
var generateOrdersServices = require('../services/generateOrders')

router.get('/get-orders', function (req, res) {

    generateOrdersServices.getOrders(function (errGenerateOrders, responseGenerateOrders) {

        if(errGenerateOrders){
            console.log(errGenerateOrders);
            res.render(errGenerateOrders);
            return;
        }
        else{
            console.log(responseGenerateOrders);
            res.render(responseGenerateOrders);
            return;
        }

    })
})

Now when I hit http://localhost:4000/generate-orders/get-orders It does not stop ever. My code generate a log file, where I add all the input and when I hit this route it keeps on adding output to the log file again and again.Also in terminal everything keeps on printing again and again.

below is my code which I am using to generate a log file for my console output:

/*************************Log Console **********************/

var log_file = fs.createWriteStream(base_log_path+'/getorders/getorders'+year+'-'+month+'-'+day+'-'+hours+'-'+minutes+'-'+seconds+'.log', {flags : 'w'});
var log_stdout = process.stdout;

console.log = function(d) { //
    log_file.write(util.format(d) + '\n');
    log_stdout.write(util.format(d) + '\n');
};
/*************************Log Console **********************/

Please suggest some solution.



via Simer

No comments:

Post a Comment