javascript - 当项目中没有 node_modules 文件夹时,Node.js 在哪里搜索模块?
问题描述
例如,在 Node.js 中创建服务器时,我无法理解 - 如果我的项目中没有 node_modules 文件夹,那么 http 模块来自哪里?
示例如下:
const http = require('http');
const onRequest = (req, res) => {
res.writeHead(200, {"Content-Type": "text/plain"});
res.write('Hello World!');
res.end();
}
const server = http.createServer(onRequest).listen(8000);
先感谢您。
附言
除了这个,我的项目文件夹中没有任何其他文件。
解决方案
如果没有节点模块,则 Node 将搜索该软件包是否已全局安装。npm install -g packageName
如果未全局安装,则会出错。
但是http
包**是节点中的**内置模块。
所以它是默认安装的,或者您不必安装它。
推荐阅读
- python - AttributeError:模块“tensorrt”没有属性“推断”
- spring - 缩放从 Web 容器中执行的 spring-batch 实例
- excel - vba modules on add-in not all available from other workbooks
- mysql - 范围之间的MySql JSON查询
- node.js - 如何正确地将 mongoDB 传递给 Node.js 中的函数
- java - 将 WAR 文件部署到 Jetty:服务器正在运行,但应用程序未启动
- maven - 执行maven Assembly插件的问题
- node.js - 使用 express-session 在 express-ws 中存储会话
- go - 无法使用私有供应商依赖进行构建
- elastic-stack - metricbeat 7.6.2 的 MSSQL 模块没有启动,并且在日志中没有错误