我在stackoverflow中搜索過,似乎沒有像我這樣的用例。我在函式目錄中有一個這樣的結構檔案夾:
函式/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;
我在這樣的檔案夾結構中創建了一個檔案:
功能/管理/功能/音樂/publisher.js
當我嘗試使用這個時,如何從 publisher.js訪問lowLevel的變數:
const lowLevel = require("../index");
而且我無法獲得對 index.js 的任何參考。有沒有辦法從根檔案夾訪問檔案 index.js?非常感謝您提供的任何提示和技巧。
uj5u.com熱心網友回復:
從這個檔案:
functions/admin/features/music/publisher.js
如果你想訪問這個檔案:
functions/index.js
你會這樣做:
const lowLevel = require("../../../index.js");
第一個..移動到functions/admin/features目錄。
第二個..移動到functions/admin目錄。
第三個..移動到functions您所說的目錄index.js。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/439989.html
標籤:javascript 节点.js
