Node.js 中的模块和包之间的区别? [英] Difference between a module and a package in Node.js?

查看:26
本文介绍了Node.js 中的模块和包之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Node.js 的新手.Node.js 中的包"和模块"有什么区别?

I am new to Node.js. What is the difference between a "package" and a "module" in Node.js?

推荐答案

Modules 是用于节点.js.请参阅以下 API 摘录:

Modules are libraries for Node.js. See the below excerpt from the API:

Node.js 有一个简单的模块加载系统.在 Node.js 中,文件和模块是一一对应的.

Node.js has a simple module loading system. In Node.js, files and modules are in one-to-one correspondence.

模块示例:

  • Circle.js
  • 矩形.js
  • Square.js

包是组合(或打包)在一起的一个或多个模块(库).这些通常由其他包或您自己的项目使用.Node.js 使用 包管理器,您可以在其中找到并安装数千个包.

A package is one or more modules (libraries) grouped (or packaged) together. These are commonly used by other packages or a project of your own. Node.js uses a package manager, where you can find and install thousands of packages.

包示例:

Shapes             <- Package name
  - Circle.js      <-
  - Rectangle.js   <- Modules that belong to the Shapes package
  - Square.js      <-

基本上,您可以安装包Shapes,并可以访问Circle、Rectangle 和Square 模块.

Essentially, you could install the package, Shapes, and have access to the Circle, Rectangle, and Square modules.

这篇关于Node.js 中的模块和包之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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