Programmers prefer a framework to develop an application or website for several reasons such as simplicity of usage, demands of the task assigned, and reliability. Node.js falls in the list of such frameworks which a developer chooses to build complex applications. It is a programme widely accepted by multi-national business giants to run their web applications. Node.js, being an extensively used platform has received many favorable as well as unfavorable remarks. Most of the times, developers who switched to Node.js, having elemental knowledge in similar programs, stumble upon several errors. Article refers certain errors a novice Node.js developers commits.
Event loop blocking
Since Node.js program is made to support complex applications, event loop happens to be a most important function. Any function written to the code which blocks the event loop will bring a wait signal to all the customers, or clients connected to the server. The program works on single thread; hence a Node.js developer should defer loops that hinder the event loop to an independent worker or queue. The problem occurs with cases such as when a developer parses functions having heavy payload with JSON. parse (), syntax highlighting done to the backend files using highlight.js, and the one-time parsing of massive files. All these are common errors in coding that lead to the blocking of an event loop. A developer can identify the error in coding which hinders the smooth working of an event loop by tracking the time delay. ‘ Blocked ’ is a proprietary open source module used to detect time delay between the functions called inside a loop. Delay occurs in the event loop should be correctly identified to spot anomalies in coding.
Triggering a call back () many times
Developers often execute a call back function twice on the process of running an application. They ignore to return a function after the instant execution. Many events in an application are triggered by passing functions as references. These references act as call backs. Call back is the only way in Node.js to make the asynchronous elements work properly. A function, in Node.js coding is added as a last argument while executing asynchronous tasks. Hence, executing a callback () many times without returning the values of first called function completely will result in a crash while dealing with Node.js . A temporary option to avoid this error is the inclusion of a return keyword ahead of executing callback functions.
Callback Hell
Call back Hell is a problem not solely associated to Node.js. It is one of the common issues which all complex frameworks have to deal with. According to the complex nature of applications, developers add nested callbacks leading to a scenario which makes things difficult to read. Maintaining of codes will be hard at this time. One of the finest options to solve this is the writing of simple functions and a proper linking of them all. To a large extent, a Node.js developer can depend on packages like Async.js, Promises, and Generators to lessen errors occur with Callback hell. Following of these modules will help programmers a lot in maintaining the codes neat and tidy.
Unawareness of development tools
Any modifications done to the source code of Node.js should be followed by a restart. Together with it, developers have a tendency to refresh the browser while static codes change leading to a slowdown in the performance of applications. There are certain modules like nodemon and forever that will help the developers to restart the server with the change of files, automatically. Similar to nodemon, livereload is another tool which aids you to refresh the browser timely after the change in static codes.
Visit source Link:
http://agriyaservices.blogspot.in/2015/08/nodejs-development-frequent-errors-made.html
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/213803
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.