I have searched in stackoverflow and it seems there isn’t any use case like mine.
I have a structure folders like this in functions directory:
functions/index.js
I added some codes to be used by other functions like this in index.js:
require("dotenv"); const admin = require("firebase-admin"); const config = JSON.parse(process.env.FIREBASE_CONFIG); admin.initializeApp(config); const highLevel = { timeoutSeconds: 300, memory: "2GB", }; const secretLevel = { timeoutSeconds: 120, memory: "1GB", secret: [process.env.SERVER_BACKEND], }; const lowLevel = { timeoutSeconds: 120, memory: "512MB", }; module.exports = lowLevel, highLevel, secretLevel;
I created a file in a folder structure like this:
functions/admin/features/music/publisher.js
How can I access the variable of lowLevel from publisher.js as I tried using this:
const lowLevel = require("../index");
and I can’t get any of reference to index.js. Is there a way to access file index.js from the root folder? Thank you very much for any tips and trick.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
From this file:
functions/admin/features/music/publisher.js
If you want access to this file:
functions/index.js
You would do that with:
const lowLevel = require("../../../index.js");
The first ..
moves up to the functions/admin/features
directory.
The second ..
moves up to the functions/admin
directory.
The third ..
moves up to the functions
directory where you say that index.js
is.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0