How to use the tmp.scraper.setup function in tmp

To help you get started, we’ve selected a few tmp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lukluk / scraper-engine / scraper-engine.js View on Github external
console.log('load script', this.dir + '/' + fileName + '.js')
    if (!fs.existsSync(this.dir + '/' + fileName + '.js')) {
      fileName = false
    }
    if (!fileName) {
      res.status(404)
      res.send('no input')
    } else {
      var script = fs.readFileSync(this.dir + '/' + fileName + '.js')
      var uniq = (new Date()).getTime()
      fileName = fileName.replace('/', '-')
      var tmp = os.tmpdir() + '/' + fileName + uniq + '.js'
      fs.writeFileSync(tmp, script, 'utf-8')
      var scr = require(tmp).scraper
        //support old ver      
      if (scr.setup) scr.onInit = scr.setup
        //support action
      if (scr.secure) {
        var token = req.body.token ? req.body.token : req.query.token
        var valid = localStorage.getItem(token)
        if (valid) {

        } else {
          res.json({
            error: true,
            message: 'token not valid'
          })
          return false
        }
      }
      if (req.params.action) {
        console.log(scr[req.params.action].toString().indexOf('res.'))