1

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

1
  • Try using import { config } from './config' to import the config file Commented Jul 1, 2020 at 14:33

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

when I'm using module.exports = config I can't access the object items from node and react.
Are you sure you are importing it right? Import it using import config from './config' and make sure to use module.exports = config
Check this sandbox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.