Last active
March 10, 2023 10:40
-
-
Save ourmaninamsterdam/ed858d1ab3710fa8c84ff0accf3ca9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.js | |
require('./a'); | |
require('./b'); | |
// mqtt.js | |
class MQTT { | |
connect() { | |
const connectionId = Math.random(); | |
console.log('connected to: ', connectionId); | |
this.connectionId = connectionId; | |
} | |
publish(message) { | |
console.log('(class) published to', message); | |
} | |
subscribe(topic){ | |
console.log('(class) subscribed to:', topic); | |
} | |
} | |
const client = new MQTT(); | |
client.connect(); | |
module.exports = client; | |
// a.js | |
const { publish, subscribe, connectionId } = require('./mqtt'); | |
publish('Hello from A'); | |
subscribe('A Topic'); | |
console.log({connectionId}); | |
// b.js | |
const { publish, subscribe, connectionId } = require('./mqtt'); | |
publish('Hello from B'); | |
subscribe('B Topic'); | |
console.log({connectionId}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running
index.js
will give you: