1. 程式人生 > >npm包上傳下載的命令及例子

npm包上傳下載的命令及例子

str div adduser pre install 修改 require all DDU

npm包上傳下載的命令及例子。

新建hello.js
執行:npm init 
執行:npm adduser
(
username:XXX
password:XXX
email:XXX

)
上傳:npm publish .
完成上傳。
測試下載:
新建一個文件夾,npm init 然後編寫index.js文件
var testnpm = require(npm-helloworld/hello.js)
var str = testnpm.sayHello();
console.log("測試結果:"+str)//測試結果:Hello,world,from 

修改包,要加版本,再npm publish .   再下載最新的代碼npm install npm
-helloworld@1.0.2 npm-helloworld包加了index.js 所以: //var testnpm = require(‘npm-helloworld/hello.js‘) var testnpm = require(npm-helloworld) var str = testnpm.sayHello(); console.log("測試結果:"+str) //測試結果:Hello,world,from 這是來自index.js文件的測試 因為默認都是找index.js 如果不是則帶上文件名字和後綴。 編寫模塊的規範要遵守: hello.js的例子: exports.sayHello
=function(){ return "Hello,world,from " } npm install npm-helloworld後,引用例子: var testnpm = require(npm-helloworld/hello.js) var str = testnpm.sayHello(); console.log("測試結果:"+str) 執行:node index.js

略。

npm包上傳下載的命令及例子