Thursday 18 May 2017

How to use "node_redis" in a phantomjs script?

I want make a phantomjs script that actuates as consumer process reading values from a redis server. I see that exists this client for node (https://github.com/NodeRedis/node_redis) and I connect, write and read without problem executing a node script.

var redis = require("redis"),
    client = redis.createClient();

client.on("error", function (err) {
    console.log("Error " + err);
});

client.set("string key", "string val", redis.print);
client.get("string key", redis.print);

But when I do the same with phantomjs I obtain this error:

ReferenceError: Can't find variable: process

  phantomjs://platform/command.js:4
TypeError: undefined is not a constructor (evaluating 'util.inherits(assert.AssertionError, Error)')

  phantomjs://platform/assert.js:161
TypeError: undefined is not a constructor (evaluating 'util.inherits(RedisError, Error)')

  phantomjs://platform/redisError.js:17
TypeError: undefined is not a constructor (evaluating 'util.inherits(ReplyError, RedisError)')

  phantomjs://platform/replyError.js:16
TypeError: undefined is not a constructor (evaluating 'util.inherits(ParserError, RedisError)')

  phantomjs://platform/parserError.js:18
ReferenceError: Can't find variable: Buffer

  phantomjs://platform/parser.js:22 in bufferAlloc
  phantomjs://platform/parser.js:8
TypeError: undefined is not a constructor (evaluating 'util.inherits(AbortError, RedisError)')

  phantomjs://platform/customErrors.js:43
Error: Cannot find module 'events'

  phantomjs://platform/bootstrap.js:299 in require
  phantomjs://platform/bootstrap.js:263 in require

Is there any way to use this package with phantomjs?



via dlopezgonzalez

No comments:

Post a Comment