开发者

packaging node.js modules with more than code

I'm putting together a module I'd like to release, but am a bit stuck on how best to go about packaging it up. In addition to server side javascript, the module will need things like an admin screen, and client side javascript files. That is, it needs to serve out a fixed set of static html/css/js files. (I may have the node-static module as a dependency)

I'm curious what is the best way to handle this. I'd like to make this simple to install and integrate into apps, without forcing the user to dig through a long README. Basically they should be able to NPM the module, then add a line or two of code in the relevant place, and have it "just work". I don't want them to have to download other stuff, tell the module where to find the static files, etc.

Also, I'd like to make sure it can be included in both simple apps (i.e开发者_Python百科. one step from the standard "hello world") as well as complex apps using frameworks etc like Express, without undue hassle.

Is this possible, or is this beyond the scope of what the module system is designed to handle?


Once your package in installed with npm install mypackage -g you can use __dirname inside your executable to find the directory it's running in.

Likely /usr/local/lib/node_modules/mypackage/bin/mypackage

With your assets in /usr/local/lib/node_modules/mypackage/assets

so __dirname + '../assets' + myasset should correctly find your asset

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜