Ali
Ali

Reputation: 1336

How to export one file to NodeJS and ReactJS?

I'm trying to export one object array file to nodeJS and ReactJS.

for example:

config.js

const config = {
  mode: "active", 
}
export default config;

I need to import this to the nodeJS file. At that time it's showing error on the export tag.

I tried this way:

    exports.config = {
      mode: "active", 
    }
    //export default config;

It's working on nodeJS. but I can't use this file to react. is there any possible way of using the same file for both.

NB: node version: v12.13.0

Upvotes: 0

Views: 319

Answers (1)

blankart
blankart

Reputation: 716

In the case of using exports.config, you can access the config file by using

import { config } from './config`

In case you want to make the config as your default export just like in export default config, use module.exports = config

Upvotes: 1

Related Questions