创建 Node.js 模块
See Details
目录
Node.js 模块是一种可以发布到 npm 的 包。
¥Node.js modules are a type of package that can be published to npm.
概述
¥Overview
创建 package.json
文件
¥Create a package.json
file
-
要创建
package.json
文件,请在命令行中,在 Node.js 模块的根目录中运行npm init
:¥To create a
package.json
file, on the command line, in the root directory of your Node.js module, runnpm init
:-
对于 范围模块,运行
npm init --scope=@scope-name
¥For scoped modules, run
npm init --scope=@scope-name
-
对于 无范围的模块,运行
npm init
¥For unscoped modules, run
npm init
-
-
为必填字段(
name
和version
)以及main
字段提供响应:¥Provide responses for the required fields (
name
andversion
), as well as themain
field:-
name
:你的模块的名称。¥
name
: The name of your module. -
version
:初始模块版本。我们建议遵循 语义版本控制指南 并从1.0.0
开始。¥
version
: The initial module version. We recommend following semantic versioning guidelines and starting with1.0.0
.
-
有关 package.json
文件的更多信息,请参阅“创建 package.json 文件”。
¥For more information on package.json
files, see "Creating a package.json file".