Find the nearest package.json in your current node module
npm install find-package``
npm install find-package
`
If you need to access the information in the package.json of your module, simply require the find-package module and pass either __dirname or process.cwd() as the directory from where to look:
`
var findPackage = require('find-package');
console.log(findPackage(__dirname).name);
//Should return the name of the current module
//as appears in the package.json
`
If you pass true as the second argument of find-package, the module will add paths object to the package.json. This object will have a relative and an absolute properties, with the correspondent relative and absolute paths to the package.json. The relative path is relative to the script calling the find-package module:
`
var package = require('find-package')(__diname, true);
package.paths.relative //string with the relative path to package.json
package.paths.absolute //string with the absolute path to package.json
``
This modules has been tested only in a UNIX environment. Although, theoretically, it should also work with Windows. If that is not the case, please let me know.