简体   繁体   English

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

[英]How to create npm package that I can include and run that package in the parent project?

I'm new to node and I created an npm package ( https://github.com/toymachiner62/node-mongo-seeds ) that I want to be able to include in another project, and then run a script with a parameter in that parent project. 我是node的新手,我创建了一个npm包( https://github.com/toymachiner62/node-mongo-seeds ),我希望能够包含在另一个项目中,然后运行带有参数的脚本那个父项目。

The script from my package that i'm trying to run is node seed . 我正在尝试运行的包中的脚本是node seed I've included this package as a dependency in my main project and when I execute $ npm seed , it doesn't work. 我已将此包作为依赖项包含在我的主项目中,当我执行$ 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

Please help point me in the right direction. 请指点我正确的方向。

You could use npm run-script . 你可以使用npm run-script

In your parent project you should be able to do npm run-script myDependencyModule seed . 在您的父项目中,您应该能够执行npm run-script myDependencyModule seed This will execute a script named "seed" defined in myDependencyModule's package.json. 这将执行myDependencyModule的package.json中定义的名为“seed”的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM