脚本宝典收集整理的这篇文章主要介绍了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
@H_126_46@module.exports = {
say() {
console.LOG('Hello World!')
}
}
npm install [Node.js Module Path] // e.g: npm install ../sayHelloWorld/
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
以上是脚本宝典为你收集整理的01.【Node.js Module】 Create a Node.js Module and Use it Locally全部内容,希望文章能够帮你解决01.【Node.js Module】 Create a Node.js Module and Use it Locally所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。