TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Your first Node.js module

74 pointsby c_t_montgomeryalmost 13 years ago

5 comments

tg3almost 13 years ago
The error that is thrown towards the end of this example should probably be passed back to the callback as an argument (e.g. callback(error, result)) instead.<p>Throwing errors in an asynchronous context can have messy results for trying to handle them. <a href="http://benno.id.au/blog/2011/08/08/nodejs-exceptions" rel="nofollow">http://benno.id.au/blog/2011/08/08/nodejs-exceptions</a> is a good explanation.
评论 #4032370 未加载
secoifalmost 13 years ago
It should also be pointed out you rarely need to edit the package.json manually:<p>npm init: Prompts for basic/common package.json entries<p>npm install --save: Install a module and place into dependencies<p>npm install --save-dev: Install a module and place into dev dependencies<p>npm install --save-optional: Install a module and place into optional dependencies<p><a href="http://blog.timoxley.com/post/22371787222/handy-new-options-for-npm-install" rel="nofollow">http://blog.timoxley.com/post/22371787222/handy-new-options-...</a>
评论 #4032386 未加载
aeurielesnalmost 13 years ago
Just for the record, I think you should have used `encodeURIComponent` instead of `encodeURI`. And in `exports.info` as well.
评论 #4033179 未加载
phase_9almost 13 years ago
I liked the part where you encouraged the developer to think about how the API will be consumed by the end user; however even a brief mention of some BDD / Unit tests here would have been nice (:
评论 #4033453 未加载
tferrisalmost 13 years ago
Slightly OT: does anyone have a good explanation for module.exports vs exports and for the expression 'exports = module.exports = someFunction' often found in modules?
评论 #4032922 未加载
评论 #4032918 未加载
评论 #4032300 未加载
评论 #4032389 未加载
评论 #4032293 未加载
评论 #4032433 未加载