node.js需要父文件夹 [英] node.js require from parent folder

查看:116
本文介绍了node.js需要父文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下结构:

-- node_modules
-- websites
---- common
------- config.js
---- testing
------- test.js

内部配置我设置了一些变量,使用module.export导出。

Inside config I have some variables set, which are being exported using module.export.

我正在尝试使用以下代码从config.js运行 node test.js 时检索这些变量:

I am trying to retrieve those variables when running node test.js from config.js using the following codes:

var configData = require('./common/config.js')
var configData = require('../common/config.js')

它们都不起作用。如何从其他文件夹中检索数据?

None of them work. What can I do to retrieve the data from the other folder?

推荐答案

var configData = require('./../common/config.js');




  1. ./ testing /

./../ 网站/

./ .. / common / 网站/普通/

./../common/config.js sites / common / config.js

这篇关于node.js需要父文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆