[英]In Node.js, How can I access exported module in Index.js?
I have searched in stackoverflow and it seems there isn't any use case like mine.我在 stackoverflow 中搜索过,似乎没有像我这样的用例。 I have a structure folders like this in functions directory:我在函数目录中有一个这样的结构文件夹:
functions/index.js函数/index.js
I added some codes to be used by other functions like this in index.js:我在 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函数/admin/features/music/publisher.js
How can I access the variable of lowLevel from publisher.js as I tried using this:当我尝试使用这个时,如何从 publisher.js 访问lowLevel的变量:
const lowLevel = require("../index");
and I can't get any of reference to index.js.而且我无法获得对 index.js 的任何参考。 Is there a way to access file index.js from the root folder?有没有办法从根文件夹访问文件 index.js? Thank you very much for any tips and trick.非常感谢您提供任何提示和技巧。
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.第一个..
向上移动到functions/admin/features
目录。
The second ..
moves up to the functions/admin
directory.第二个..
向上移动到functions/admin
目录。
The third ..
moves up to the functions
directory where you say that index.js
is.第三个..
向上移动到您所说的index.js
所在的functions
目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.