--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Why not just use `var packageJson = require(__dirname + '/package.json');` to get configuration object without parsing.
You can require the json, freeze the object to get read only, and wrap a little module around it with some convenience methods...
There is no absolute best way to do that.
require caches the content of the file after the first access. Calls to require after the first one will just return the cached content, and the file will not be parsed again. Use this approach if you expect that the content of the file never change during the execution time of your application.
If you read and parse the file manually you are in charge of controlling if you want to reload the content every time you access it or if you want to cache its content. In addition, programmatically reloading the file doesn't necessarily require your application to be restarted.
If you choose the manual approach, it may not be required to access the file asynchronously. If the file contains configuration information that are needed to start your main application you can also use synchronous code. There is usually no "concurrency" to handle during the startup phase of your application.
Yep, agree with Arya and Nick, using require() is the best way to do it. I've used it on several modules to good effect.
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/a9d6ca81-30ea-43ea-b7da-7c9113ae94dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.