如何创建我可以包含的npm包并在父项目中运行该包?

时间:2014-05-07 17:00:34

标签: javascript node.js npm

我是node的新手,我创建了一个npm包(https://github.com/toymachiner62/node-mongo-seeds),我希望能够包含在另一个项目中,然后在该父项目中运行带有参数的脚本。 / p>

我尝试运行的程序包中的脚本是node seed。我已将此软件包作为依赖项包含在我的主项目中,当我执行$ npm seed时,它无法正常工作。

$ npm seed

Usage: npm <command>

where <command> is one of:
    add-user, adduser, apihelp, author, bin, bugs, c, cache,
    completion, config, ddp, dedupe, deprecate, docs, edit,
    explore, faq, find, find-dupes, get, help, help-search,
    home, i, info, init, install, isntall, issues, la, link,
    list, ll, ln, login, ls, outdated, owner, pack, prefix,
    prune, publish, r, rb, rebuild, remove, repo, restart, rm,
    root, run-script, s, se, search, set, show, shrinkwrap,
    star, stars, start, stop, submodule, tag, test, tst, un,
    uninstall, unlink, unpublish, unstar, up, update, v,
    version, view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    C:\Users\m089269\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

请指点我正确的方向。

1 个答案:

答案 0 :(得分:2)

您可以使用npm run-script

在您的父项目中,您应该能够npm run-script myDependencyModule seed。这将执行一个名为&#34; seed&#34;的脚本。在myDependencyModule的package.json中定义。