01.【Node.js Module】 Create a Node.js Module and Use it Locally

I'm practicing my English ability lately in order to be recruited by a foreign company for my next job-hopping,if there is anything that I did't express precisely, please pardon me.

How to Create a Node.js Module

1. Create a new directory and enter it.

e.g:/d/sayHelloWorld

2. Init your Node.js module.

You will set name, descrption, entry point and etcetera for your Node.js module.
When you are done, there will be a new file in your directory called "package.json", which contains all of the information you just set.
entry point: your entry file of your Node.js module.
test command: the command that you need to execute your unit test.
npm init

3. Create your entry point.

e.g:/d/sayHelloWorld/index.js

module.exports = {
    say() {
    console.log('Hello World!')
   }
}

How to use your Node.js Module Locally

1. Create a new directory and enter it.

2. Install the Node.js module that you created before.

npm install [Node.js Module Path]   // e.g: npm install ../sayHelloWorld/

3. Enter into the Node shell interface, and test if your Node.js Module is available to use.

node
var test = require([Node.js Module Name]) // e.g: var test = require('sayhelloworld')
test.say() // write out 'Hello World'

Related:
Publish a Node.js Module to the NPM Registry
Install Pakages Using NPM

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值