[英]how to access parent module data in child file in node.js
var name=require('../sample.js')
console.log(name.h);
您需要父目錄中帶有“ ..”的模塊
當你需要使用相對路徑的文件,它是相對於文件做require
(見這里 )。 在test.js
, require('./sample.js')
將查找/path/to/xx/sample.js
。 使用require('../sample.js')
因為它位於test.js
的父文件夾中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.