Node.js require(';.';)是什么意思?

Node.js require(';.';)是什么意思?,node.js,Node.js,我是node.js的新手,一直在尝试使用Thread测试一些代码。目前,我正在使用以下代码: const assert = require('assert') const username = process.env.HDFS_USERNAME || 'webuser' const endpoint1 = process.env.HDFS_NAMENODE_1 || 'namenode1.lan' const endpoint2 = process.env.HDFS_NAMENODE_2 ||

我是node.js的新手,一直在尝试使用Thread测试一些代码。目前,我正在使用以下代码:

const assert = require('assert')
const username = process.env.HDFS_USERNAME || 'webuser'
const endpoint1 = process.env.HDFS_NAMENODE_1 || 'namenode1.lan'
const endpoint2 = process.env.HDFS_NAMENODE_2 || 'namenode2.lan'
const homeDir = `/user/${username}`
const basePath = process.env.HDFS_BASE_PATH || homeDir
const nodeOneBase = `http://${endpoint1}:9870`
const nodeTwoBase = `http://${endpoint2}:9870`

const webhdfs = require('..')

const should = require('should')
const nock = require('nock')

describe('WebHDFSClient', function () {

  const oneNodeClient = new (require('..')).WebHDFSClient({
    namenode_host: endpoint1
  });
})
我从这份回购协议中得到:

当我尝试运行
纱线测试时
会出现以下错误:

Cannot find module '..'
Require stack:
- myrepo/test/lib/hdfs.js
- myrepo/test/tests.js
- myrepo/node_modules/mocha/lib/mocha.js
- myrepo/node_modules/mocha/index.js
- myrepo/node_modules/mocha/bin/_mocha
  Error: Cannot find module '..'

正如您所看到的,
require(“..”)
在代码中被使用了好几次,我无法理解它的含义。我在
require('../')
上找到了帖子,我认为这篇帖子与这篇文章不完全相同。

内置的node.js
require
函数使用了一个非常复杂的包解析算法。所以有很多事情可能会影响它

A.默认为
index.js
如果未指定文件名,node.js隐式需要名为
index.js的文件

所以
require(“…”
转换为
require(../index.js”)

B.
包属性。 如果
require
位于模块内部并指向模块的根目录,它将从packages
package.json
中读取
main
属性,并需要在其中指定的文件

因此给出了这个包定义(
package.json

require(“…”
的调用将转换为
require(../fileA.js”)

资源


根据我在这里读到的内容,我认为这与
require(“..”)
不同:但我可能错了。让我惊讶的是这行代码中的情况:
const-oneNodeClient=new(require(“..”).WebHDFSClient({
@ahajib)这个包与这个问题关系不大,因为您需要一个来自
node\u modules
内部的模块。您对这行有什么支持?您更新的响应对我来说更有意义。谢谢
{
    "main": "./fileA.js"
}