Y
Y
Yurik7k2018-02-18 11:27:14
Node.js
Yurik7k, 2018-02-18 11:27:14

How to execute exec command from platformjs?

I am writing a program on phantomjs, after working out the phantomjs script, it is necessary to save the received information.
Initially, in the script that launches phantomjs, I tried to call mysql and save the data to a table, I run it like this:
phantomjs goview.js
then I call the save function in the goview.js logic:
this is a separate fn.js file

var mysql = require('mysql');

module.exports.saveTasks2 = function(module, tasks){

    var connection = mysql.createConnection({
        host     : '127.0.0.1',
        user     : 'root',
        password : '',
        database : 'phantom_muse'
    });

    var insert = {name_modele_parse: module, json_task: JSON.stringify(tasks)}

    var query = connection.query('INSERT INTO tasks SET ?', insert, function(err, result) {

        console.log(err);
        console.log(result);

        if(err===null){
          console.log("OUT>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
          console.log(tasks)
          connection.end();
          return true;
      }
      else
      {
        console.log('error save')
        connection.end();
        return false;
    }    
});
}

as a result, this command gives me module connection errors:
Error: Cannot find module 'crypto'

  phantomjs://platform/bootstrap.js:299 in require
  phantomjs://platform/bootstrap.js:263 in require
  phantomjs://platform/Connection.js:2
Error: Cannot find module 'url'

  phantomjs://platform/bootstrap.js:299 in require
  phantomjs://platform/bootstrap.js:263 in require
  phantomjs://platform/ConnectionConfig.js:2
TypeError: Object is not a constructor (evaluating 'new ConnectionConfig(config)')

  phantomjs://platform/index.js:14 in createConnection
  phantomjs://platform/api.js:8 in saveTasks2
  phantomjs://platform/pagin.parsero.js:29 in parse

in general, rummaging through the net, I came to the following: use exec (executive module)
but the exec command is not launched from under phantomjs. in general, wherever you go, there is a fence everywhere that I cannot climb over.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-02-18
@dimonchik2013

https://vk.com/video-35222075_161992587
what, you can't save the result to an object / list and then work with it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question