Skip to content Skip to sidebar Skip to footer

Node Js Console.log Is Not Showing Anything

I'm trying to scrap a webpage using node js.I think I've written the code and was able to run it without any errors but the problem is the console doesn't print anything no matter

Solution 1:

To be sure that your console.log work correctly just try it like that :

console.log('starting');//<--------------------------------------- added linevar fs         = require('fs');
var request    = require('request');
var cheerio    = require('cheerio');

var htmlString = fs.readFileSync('scrap.html').toString();
var $          = cheerio.load(htmlString);
var json = [];

console.log('htmlString : ' + htmlString );//<-------------------- added line


$('body > table:nth-child(1) > tbody > tr:nth-child(3) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr > td > table > tbody > tr').each(function(i, element) {
    json.push({});
    json[i].range = $(this).text().trim();

});

console.log('Elements in json : ' + json.length);//<-------------- added lineconsole.log(json);

If this don't produce anything on the server-side, so yes we can confirm that your console.log don't work as expected, else it works and the problem come from other things !

Hope this will help you.

Post a Comment for "Node Js Console.log Is Not Showing Anything"