Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$node pubsub.js issue. Lecture 37 #14

Open
JoshSoltys opened this issue Oct 14, 2021 · 0 comments
Open

$node pubsub.js issue. Lecture 37 #14

JoshSoltys opened this issue Oct 14, 2021 · 0 comments

Comments

@JoshSoltys
Copy link

JoshSoltys commented Oct 14, 2021

Lecture 37 when i run node pubsub.js i get the following error in the console. I believe I installed redis correctly. I get "Configuration loaded" after running redis-server --daemonize yes. I will also include my code from the pubsub class. Thanks for any help.

josh@Josh:~$ node pubsub.js

internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module '/home/josh/pubsub.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

const redis = require('redis');

const CHANNELS = {
    TEST: 'TEST'
};


class PubSub {
    constructor(){
        this.publisher = redis.createClient();
        this.subscriber = redis.createClient();

        this.subscriber.subscribe(CHANNELS.TEST);

        this.subscriber.on(
            'message', 
            (channel, message) => this.handleMessage(channel, message)
        );
    }

    handleMessage(channel, message) {
        console.log(`Message received. Channel: ${channel}. Message: ${message}.`);
    }
}

const testPubSub = new PubSub();

testPubSub.publisher.publish(CHANNELS.TEST, 'foo');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant