简体   繁体   English

对于Node.JS,Win中的核心模块在哪里?

[英]For Node.JS, where are the core modules in Win?

From the official api site it says that core modules are installed at the /lib folder of the root folder of NodeJS, but when I was trying to search for it I didn't see the /lib folder. 官方api网站上,它说核心模块安装在NodeJS根文件夹的/ lib文件夹中,但是当我尝试搜索它时,却没有看到/ lib文件夹。

Any idea? 任何想法?

Additionally, after I've done a 另外,在我完成

var a = require("a.js");

is it possible to get the corresponding path to a.js? 是否有可能获得a.js的相应路径?

that means /lib folder is in source code not your computer. 这意味着/lib文件夹位于源代码中,而不是您的计算机中。 you can see it in repository . 您可以在存储库中看到它。

and

there are two patterns for require 有两种模式require

  • absolute path: if the parameter is not started with ./' nor '../', it's absolute path. 绝对路径:如果参数不是以./' nor '../'开头,则为绝对路径。 so node look for it in core module(it's compiled in node runtime) or `node_modules' that you installed locally using npm. 因此,节点会在您使用npm在本地安装的核心模块(在节点运行时中编译)或“ node_modules”中查找它。

  • relative path: if the parameter is started with ./ or ../ , it's relative path. 相对路径:如果参数以./../开头,则为相对路径。 so node look for it relative path to current position. 所以节点寻找它到当前位置的相对路径。

it's so simple. 很简单。 and you can use require.resolve('a.js') to get absolute system path. 您可以使用require.resolve('a.js')获得绝对系统路径。 but core modules don't has path since it's built-in. 但是核心模块是内置的,因此没有路径。

Although the accepted answer is good enough to resolve the question, it is worth mention that it has some misleading information regarding the patterns of required. 尽管已接受的答案足以解决问题,但值得一提的是,它具有一些有关所需模式的误导性信息。 From the very Reference Documentation of Node : Node的参考文档中

A module prefixed with '/' is an absolute path to the file. 前缀为“ /”的模块是文件的绝对路径。 For example, require('/home/marco/foo.js') will load the file at /home/marco/foo.js. 例如,require('/ home / marco / foo.js')会将文件加载到/home/marco/foo.js。

A module prefixed with './' is relative to the file calling require(). 前缀为“ ./”的模块相对于调用require()的文件。 That is, circle.js must be in the same directory as foo.js for require('./circle') to find it. 也就是说,circle.js必须与foo.js位于同一目录中,以便require('./ circle')可以找到它。

Without a leading '/' or './' to indicate a file, the module is either a "core module" or is loaded from a node_modules folder. 如果没有以“ /”或“ ./”开头的文件,则该模块要么是“核心模块”,要么是从node_modules文件夹加载的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM