0

I want to publish a nodejs public repo on github as NPM package, to be installed globally, with

npm install -g mypackage

The package contains also some executables and some source code files (example programs) in the example directory:

examples/file_1.js
examples/file_2.js

What's the correct way to let access LOCALLY (without access the github repo) these example files, to a user that installed the package?

examples files are in directory: .../node_modules/examples, I so could suggest to read the files at:

echo `npm root -g`/mypackage/examples

Make sense? Any cleaner solution? thx

Giorgio Robino
  • 2,148
  • 6
  • 38
  • 59
  • Thx. Nevertheless I don't understand how user that installed the package can access (make a copy of) distribution files declared in "files" package.json section. – Giorgio Robino Sep 04 '20 at 14:00
  • 1
    Perhaps you could print a message in a `postinstall` script? – customcommander Sep 04 '20 at 15:15
  • 1
    The files will be there in `.../node_modules/yourpackage`. – AKX Sep 04 '20 at 15:38
  • @customcommander do you mean by example running with `npm run postinstall` (https://stackoverflow.com/questions/31000392/npm-how-to-just-run-post-install) a bash script like echo "Example files are in directory:"; echo \`npm root -g\`/mypackage/examples ? – Giorgio Robino Sep 06 '20 at 14:37
  • 1
    @GiorgioRobino Yep except that you wouldn't need to run it manually. It's automatically done for you _after_ the installation of a package. i.e. after `npm install ` – customcommander Sep 06 '20 at 16:41
  • The solution I found good for me: as suggested I made a `postinstall` node script that print to stdout a sort of README where I remind package user that examples are under directory `npm root -g`/mypackage/examples . BTW I do not agree about the fact my question is a duplicate of https://stackoverflow.com/questions/31642477/how-to-publish-a-npm-package-with-distribution-files (never mind). – Giorgio Robino Sep 18 '20 at 10:52

0 Answers0