Search code examples
node.jsgoogle-trends

Node.js is crashing/exiting without any error message in minified npm package, how to debug?


I'm using a library google-trends-api and for some reason it's causing node to exit without any error. Just a clean errorless exit. The try/catch is ignored. I'm quite confused as this has never happened to me in 3 years of using node.

Here's the code, not that it matters much:

  let res
  try {
    res = await googleTrends.interestOverTime({
      keyword: ['something', keyword],
      geo: 'EN',
      startTime: new Date(getDaysAgoTimestamps(365)),
      agent: proxyAgent
    })
    debug({res})
    res = JSON.parse(res)
  }
  catch (e) {
    debug('getTrendsAverages error')
    debug(e)
  }

My question is, how can I even begin to debug this? I tried to look at the lib in node modules but it's minified.


Solution

  • Try adding the following error-handling functions as they will provide more detail about your problem.

    
    process.on('unhandledRejection', (reason, promise) => {
        console.log(reason)
    })
    process.on('uncaughtException', (reason) => {
        console.log(reason)
    })