什么是Node.js的模块(Module)?node
在Node.js中,模块是一个库或框架,也是一个Node.js项目。Node.js项目遵循模块化的架构,当咱们建立了一个Node.js项目,意味着建立了一个模块,这个模块的描述文件,被称为package.json。git
一般状况下若是 package.json内容出错,会致使项目出现bug,甚至阻止项目的运行。github
因此在修改该文件时候必定要当心,格式,名称等是否正确npm
上述参数是极为常见的参数,另外还能够设置script、license等等。除了官方必须的一些参数外,咱们也能够存储咱们本身的关于模块的描述信息在package.json。json
可使用npm生成package.json文件,它能够包含最基本的设置以及结果。bash
例如:运行markdown
npm init
This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help json` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg> --save` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. name: (node_modules) runoob # 模块名 version: (1.0.0) description: Node.js 测试模块(www.xxxxx.com) # 描述 entry point: (index.js) test command: make test git repository: https://github.com/xxxxx/xxxxx.git # Github 地址 keywords: author: license: (ISC) About to write to ……/node_modules/package.json: # 生成地址 { "name": "runoob", "version": "1.0.0", "description": "Node.js 测试模块(www.runoob.com)", …… # 其余参数 } Is this ok? (yes): yes
最后输入yes架构
这样就生成了一个最基本的package.json文件。框架
手动更改的时候要彻底遵循严格的JSON书写格式,不然容易出现意想不到的简单错误。ide