I have imported a module to another module and called it in that module and its working nicely but i want to store data which is in my imported module how to i do that? please help
This is the code of the module which got imported
async function dfuseListener()
{
const client = createDfuseClient({
apiKey: 'mobile_47115651c24f79d220184dae661259df',
network: "jungle",
httpClientOptions: {
fetch: nodeFetch,
},
streamClientOptions: {
socketOptions: {
webSocketFactory: async (url) => {
console.log("hiiiiiii")
const webSocket = new WebSocket(url, {
handshakeTimeout: 30 * 1000, // 30s
maxPayload: 200 * 1024 * 1000 * 1000 // 200Mb
})
const onUpgrade = (response) => {
console.log("Socket upgrade response status code.", response.statusCode)
// You need to remove the listener at some point since this factory
// is called at each reconnection with the remote endpoint!
webSocket.removeListener("upgrade", onUpgrade)
}
webSocket.on("upgradeurl", onUpgrade)
return webSocket
}
}
}
})
const onMessage = (message) => {
console.log('onMessage :')
console.log('im working ',message);
if (message.type === InboundMessageType.PROGRESS) {
// updateProgress(networkName, message);
} else if (message.type === InboundMessageType.ACTION_TRACE) {
// updateAction(message.data);
} else {
console.log(message);
}
}
const stream = await client.streamActionTraces(
{
accounts: "guru11111111"
},
onMessage, {
start_block: 52797826,
with_progress: 60
}
)
console.log("Socket is now connected.")
}
module.exports=dfuseListener;
I'm calling dfuseListener in my other module and it printing the value in console
console.log('im working ',message); i want to access the value of message in my other module and store it in mongodb
Is there any way i can access that ?
this is the 2nd module in which i want to access the imported module data
const MongoClient = require('mongodb').MongoClient;
const express =require('express')
const app =express();
const dfuseListener = require('./dfuse');
dfuseListener();
console.log('dfuse product: ',dfuseListener.onMessage)//Its giving undefine
app.get('/',(req,res)=> {
res.send("hey its working ..")
})
app.listen(9000);
const uri = "mongodb+srv://abc:123@cluster0-z2ii6.mongodb.net/test?retryWrites=true&w=majority"
MongoClient({ useUnifiedTopology: true });
MongoClient.connect(uri,{ useNewUrlParser: true },{ useUnifiedTopology: true },function(err, client) {
if(err) {
console.log('Error occurred while connecting to MongoDB Atlas...\n',err);
}
console.log('Connected...');
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close();
});