#1. Create a somepackage folder
#2. Create an index. js file under somepackage
#3. Write data to a file
exports.hello=function(){console.log('Hello World');};
#5. Write
var somepackage=require('./somepackage');somepackage.hello();
{"main":"./lib/interface.js"}
exports.hello=function(){console.log('Hello Node.js');};
Parts should contain the following fields.
Character name: the name of the package. It must be unique and consist of lowercase letters, numbers, and underscores. It cannot contain spaces.
Brief description: a brief description of the package.
Semantic version: A version string that complies with the semantic version recognition ① specification.
Keywords: a keyword array, which is usually used for search.
Inclumaintainers: the maintainer array. Each element must contain the name, email (optional), and web (optional) fields.
Contributor contributors: A contributor array in the same format as maintainers. The package author should be the first element of the contributor array.
Bugs: the address for submitting a bug. It can be a URL or email address.
License licenses: A license array. Each element must contain the type (license name) and url (link to the license text address) fields.
Repository repositories: A repository hosting address array. Each element must contain the type (repository type, such as git), url (repository address), and path (optional) fields.
{"name": "mypackage","description": "Sample package for CommonJS. This package demonstrates the requiredelements of a CommonJS package.","version": "0.7.0","keywords": ["package","example"],"maintainers": [{"name": "Bill Smith","email": "bills@example.com",}],"contributors": [{"name": "BYVoid","web": "http://www.byvoid.com/"}],"bugs": {"mail": "dev@example.com","web": "http://www.example.com/bugs"},"licenses": [{"type": "GPLv2","url": "http://www.example.org/licenses/gpl.html"}],"repositories": [{"type": "git","url": "http://github.com/BYVoid/mypackage.git"}],"dependencies": {"webkit": "1.2","ssl": {"gnutls": ["1.0", "2.0"],"openssl": "0.9.8"}}}
#1. Obtain the npm [install/I] [package_name] package and place it in the node_modules subdirectory of the current directory. #2. In local mode and global mode, the npm install command is used by default to install the package to the node_modules subdirectory in the current directory. The Node. js require will automatically search for the node_modules subdirectory. Npm also has a different installation mode called Global mode. Usage: npm [install/I]-g [package_name]
{"Name": "one", "version": "0.1.0", "description": "Test File", "main": "main. js "," scripts ": {" test ":" test. js "}," repository ": {" type ":" git "," url ":" 1234 "}," keywords ": [" one "," node. js "]," author ":" mrge. ge "," license ":" BSD-2-Clause "}In this way, we made a simple package. Before release, we also need to obtain an account for future maintenance of our own package. Use npm adduser to enter the user name, password, and email address as prompted, and wait until the account is created. After that, you can use npm whoami to test whether an account has been obtained. In this way, a user is successfully created.