A
A
Andrey Sobolev2020-06-17 16:05:52
Node.js
Andrey Sobolev, 2020-06-17 16:05:52

How to use object of one file in another?

There is a methods.js file that contains an object

const OBJECT = {
    mainFunction: () => {
        retrun 'blablabla';
    }
};


And there is another app.js file in which the constant is used
let a = OBJECT.mainFunction;

. No matter how I tried to do
import 'methods'or import OBJECT from 'methods'and export before const added, the app.js file does not see OBJECT.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-06-17
@Kozack

Or

// 
const { OBJECT } = require("./methods");

//
module.exports = {
  OBJECT: {
    mainFunction: () => {
      return "blablabla";
    }
  }
};

Or
// 
import { OBJECT } from "./methods";

//
export const OBJECT = {
  mainFunction: () => {
    return "blablabla";
  }
}

Depends on what environment you are running in (what version of node, how webpack is configured, etc.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question