How do I make my npm package include a file called template.html
, and then once the package has been globally installed, how will my node javascript app find the path to that file in order to load it from disk?
By default, NPM will include all the files in your directory when packaging. (You can control that with files
property in package.json
.)
When your package is installed, if you have template.html
in the same directory as your script file, you can use __dirname
to access it:
fs.readFile(path.resolve(__dirname, 'template.html'), 'UTF-8', callback);
(source)