node.js - What are common development issues, pitfalls and suggestions? -
i've been developing in node.js 2 weeks , started re-creating web site written in php. far good, , looks can same thing in node (with express) done in php in same or less time.
i have ran things have used such using modules, modules not sharing common environment, , getting habit of using callbacks file system , database operations etc.
but there developer might discover lot later pretty important development in node? issues else developing in node has don't surface until later? pitfalls? pros know , noobs don't?
i appreciate suggestions , advice.
here things might not realize until later:
- node pause execution run garbage collector eventually/periodically. server pause hiccup when happens. people, issue not significant problem, can barrier building near-time systems. see does node.js scalability suffer because of garbage collection when under high load?
- node single process , default use 1 cpu. there built-in clustering support run multiple processes (typically 1 per cpu), , part node community believes solid approach. might surprised reality, though.
- stack traces lost due event queue, logging , debugging methodology needs change significantly
here minor stumbling blocks may run while (i still bump against these)
- remembering
callback(null, value)on successful callback. passing null first parameter weird , forget it. instead accidentallycallback(value), interpreted error caller until debug while , slap forehead. - forgetting use
returnwhen invoke callback in guard clause , don't want function continue execute past point. results in callback getting invoked twice, causes manner of misbehavior.
here nice things might not realize initially
- it easier in node.js, using 1 of awesome flow control libraries, complex operations loading 3 network resources in parallel, making 2 db calls in serial, writing 2 log files in parallel, sending http response. stuff trivial , beautiful in node , damn near impossible in many synchronous environments.
- all of node's modules new , modern, , part, can find beautifully-designed module great api need. python has great libraries now, too, compare node's cheerio or jsdom module python's beautifulsoup , see mean. compare python's
requestsmodule node'ssuperagent. - there's community benefit comes working modern platform people focused on modern web development. contrast between node community , php community cannot overstated.
Comments
Post a Comment