Re:Ask HN: How do you write clean node.js code?
by mparke on Wednesday May 11, 2011 @09:20PM
(#2539150)
Question, How many modules is your server broken up into? Are you utilizing exports?
[ Parent
| on HN ]
Re:Ask HN: How do you write clean node.js code?
by michael_miller on Wednesday May 11, 2011 @09:24PM
(#2539159)
The server is pretty monolithic; the majority of the code lives in a single file, with two modules taking care of some code which we share between servers.
Re:Ask HN: How do you write clean node.js code?
by mparke on Wednesday May 11, 2011 @09:32PM
(#2539169)
my first suggestion is then to break your server up into more modules, which should improve your situation. I'm fairly new to node, but currently building a few different apps. I'd recommend reading nodebeginner.org , you can also check out a Node Server git repo i just created tonight, implemented based on that tutorial. https://github.com/mparke/Node-Server-Exploration
Feel free to contact me if you want to chat more. I'd love to hear about your experiences with Node.
Re:Ask HN: How do you write clean node.js code?
by michael_miller on Wednesday May 11, 2011 @09:55PM
(#2539223)
This definitely feels like something that will help a lot. I tend to be doing similar things in many places of my code, like getting the current user's document from the user DB, and handling errors in the same way(by passing {error: "description"} and a status code of 500 back to the client). By factoring out shared/similar code into a library, I think the code will get a lot cleaner. Thanks for the suggestion!