I am looking to use an already logged-in twitter client from my index.js file by exporting it and then simply calling it for use in another js file, I'll just call it file2.js
index.js:
const twit = require('twit'); const TwitterClient = new twit({ consumer_key: `${process.env.TWITTER_KEY}`, consumer_secret: `${process.env.TWITTER_SECRET}`, access_token: `${process.env.TWITTER_TOKEN}`, access_token_secret: `${process.env.TWITTER_TOKENSECRET}`, timeout_ms: 60 * 1000, strictSSL: true }) module.exports = TwitterClient; file2.js:
const { TwitterClient } = require('../../index') TwitterClient.get('users/lookup', { screen_name: 'Plexversal' }).then(a => { console.log(a) }) From what I have already tried to research this should be what I do, the path to the index file is correct as I can see the exported class when I hover over it so I know that's not the issue.
The error that I get from file2 is:
Cannot read property 'get' of undefined
The exact same function works in the index file and I tried the most basic of methods to get some kind of output with no luck so the syntax is valid. I just want to know what i'm missing.
Thanks.
https://stackoverflow.com/questions/65877439/js-how-do-i-use-an-initialized-class-in-another-file January 25, 2021 at 08:20AM
没有评论:
发表评论