Node.js (npm) accessing files inside installed module -


i implementing node module , i'd users optionally able require files part of module. example :

var m = require('my-module'); var foo = require('my-module/foo'); 

considering module structure :

./my-module   +- lib   |  +- foo   |  |  +- index.js   |  +- index.js   +- package.json 

and basic package.json file :

{   "name": "my-module",   "version": "0.0.1",   "description": "my own super fun module.",   "main": "lib/index.js" } 

note: unecessary keys omitted clarity, ex: dependencies, keywords, author, etc.

how package.json can modified allow "feature"?

change module structure this:

./my-module   +- lib   |  +- foo   |  |  +- index.js   |  +- index.js   +- index.js   +- foo.js   +- package.json 

or better, change require('my-module/foo') require('my-module').foo of modules do.

setting main in package.json wrong thing (because package.json npm's own metadata , shouldn't have node.js, think installing package bower example), shouldn't using anyway.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -