Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write "module.exports" from javascript to typescript?

How do I convert the JavaScript module.exports to typescript

The JavaScript code of the module.exports is :

module.exports = {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
};
like image 261
Anup Bhattarai Avatar asked Jun 30 '26 01:06

Anup Bhattarai


2 Answers

use export default

const val = {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
};
export default val
like image 107
Vignesh Avatar answered Jul 01 '26 14:07

Vignesh


Try to use the export default keyword:

export default {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
}

You can also export single elements (equivalent of module.exports.foo = { ... }):

export const foo = {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
}
like image 23
pierreavn Avatar answered Jul 01 '26 15:07

pierreavn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!