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

StackOverflow https://stackoverflow.com/questions/23523909

  •  17-07-2023
  •  | 
  •  

Question

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.

The script from my package that i'm trying to run is 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

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.

Était-ce utile?

La solution

You could use npm run-script.

In your parent project you should be able to do npm run-script myDependencyModule seed. This will execute a script named "seed" defined in myDependencyModule's package.json.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top