最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何在我的主项目中使用我的私人npm软件包

IT培训 admin 9浏览 0评论

如何在我的主项目中使用我的私人npm软件包

我正在创建私有npm,并在this的帮助下使用sinopia将其发布到本地npm存储库中>

。storage树在下面

C:\sinopia
    \ storage
      \privateProj
          package.json
          privateProj1.0.1.taz

我在主项目位置运行了以下命令

npm install privateProj --save

它将更新package.json如下

   {
  "name": "privateprojectClient",
  "version": "1.0.0",
  "description": "",
  "main": "myApp.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "privateProj": "^1.0.1"
  }
}

然后按照imag将privateProj下载到nodemodule文件夹中然后我尝试运行节点myapp.js它显示以下消息

I:\NodeJSProject\privateprojectClient>node myApp.js

module.js:340
    throw err;
          ^
Error: Cannot find module '/node_modules/privateProj'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (I:\NodeJSProject\privateprojectClient\myApp.js:5:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

privatePro / app.js中的代码是

var db = require('diskdb');

db.connect('./examples/db', ['articles','comments','users']);

var article1 = {
    title : 'diskDB rocks',
    published : 'today',
    rating : '5 stars'
}

var article2 = {
    title : 'diskDB rocks',
    published : 'yesterday',
    rating : '5 stars'
}

var article3 = {
    title : 'diskDB rocks',
    published : 'today',
    rating : '4 stars'
}
db.articles.save([article1, article2, article3]);

var articleComments = {
    title: 'diskDB rocks',
    published: '2 days ago',
    comments: [{
        name: 'a user',
        comment: 'this is cool',
        rating: 2
    }, {
        name: 'b user',
        comment: 'this is ratchet',
        rating: 3
    }, {
        name: 'c user',
        comment: 'this is awesome',
        rating: 2
    }]
}

dbments.save(articleComments);



var printFruits = function() {
    console.log(db.articles.find());
}

// To test the app locally
 //npm publishprintFruits(); // << uncomment this
// and run
// $ node app.js

exports.printFruits = printFruits;

我正在创建私有npm,并借助sinopia将其发布到我的本地npm存储库中,.storage树位于C:\ sinopia \ storage \ privateProj package.json下面。

Node“ require”函数将默认在node_modules中查找,请尝试 回答如下:并将node_modules / privateProj / app.js重命名为node_modules / privateProj / index.js

如何在我的主项目中使用我的私人npm软件包

我正在创建私有npm,并在this的帮助下使用sinopia将其发布到本地npm存储库中>

。storage树在下面

C:\sinopia
    \ storage
      \privateProj
          package.json
          privateProj1.0.1.taz

我在主项目位置运行了以下命令

npm install privateProj --save

它将更新package.json如下

   {
  "name": "privateprojectClient",
  "version": "1.0.0",
  "description": "",
  "main": "myApp.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "privateProj": "^1.0.1"
  }
}

然后按照imag将privateProj下载到nodemodule文件夹中然后我尝试运行节点myapp.js它显示以下消息

I:\NodeJSProject\privateprojectClient>node myApp.js

module.js:340
    throw err;
          ^
Error: Cannot find module '/node_modules/privateProj'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (I:\NodeJSProject\privateprojectClient\myApp.js:5:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

privatePro / app.js中的代码是

var db = require('diskdb');

db.connect('./examples/db', ['articles','comments','users']);

var article1 = {
    title : 'diskDB rocks',
    published : 'today',
    rating : '5 stars'
}

var article2 = {
    title : 'diskDB rocks',
    published : 'yesterday',
    rating : '5 stars'
}

var article3 = {
    title : 'diskDB rocks',
    published : 'today',
    rating : '4 stars'
}
db.articles.save([article1, article2, article3]);

var articleComments = {
    title: 'diskDB rocks',
    published: '2 days ago',
    comments: [{
        name: 'a user',
        comment: 'this is cool',
        rating: 2
    }, {
        name: 'b user',
        comment: 'this is ratchet',
        rating: 3
    }, {
        name: 'c user',
        comment: 'this is awesome',
        rating: 2
    }]
}

dbments.save(articleComments);



var printFruits = function() {
    console.log(db.articles.find());
}

// To test the app locally
 //npm publishprintFruits(); // << uncomment this
// and run
// $ node app.js

exports.printFruits = printFruits;

我正在创建私有npm,并借助sinopia将其发布到我的本地npm存储库中,.storage树位于C:\ sinopia \ storage \ privateProj package.json下面。

Node“ require”函数将默认在node_modules中查找,请尝试 回答如下:并将node_modules / privateProj / app.js重命名为node_modules / privateProj / index.js
发布评论

评论列表 (0)

  1. 暂无评论