Node is programmed using JavaScript, a language familiar to web development professionals. JavaScript’s syntax and naming conventions are influenced by C and Java, but the language is higher-level, meaning it generally takes less lines of code in JavaScript to express the equivalent C or Java logic. Despite JavaScript’s comparative brevity, however, it is powerful. In its early years, JavaScript was disparaged due to incompatibilities between browser implementations and difficulty of debugging, but, as time went on, implementations improved and the expressiveness of the language gained appreciation.
JavaScript is excellent for specifying asynchronous logic because functions are “first-class objects.” This means the language allows functions themselves to be passed as function arguments, used as return values, and assigned to variables.
Callback functions are used to specify asynchronous logic. A callback is a function argument that contains a reference to program logic. Callbacks indicate an action to take when a programming event occurs or after intermediary logic is completed. JavaScript’s callback syntax is very elegant: either a function name or syntax- defining function logic can be passed as a callback.
JavaScript also has the advantage of being portable between the browser and the server. As long as any APIs accessed by logic are available on both the browser and the server, the same logic should run in either environment. Form validation, for example, is often duplicated on the client and the server. Why write the same code twice? Reusing logic on both the browser and the server enforces consistency and means not having to reinvent the wheel. It also means you have to maintain less code. Another benefit is you don’t have to mentally context-switch between languages when working on different parts of a web application. Staying in one language is likely to increase your productivity and make development more enjoyable.
Web applications are just the beginning
Node can develop much more than web applications. Node is also a good fit for designing servers, protocols, and command-line applications.
Server applications such as file transfer, email delivery, and instant messaging applications have traditionally been created in non-dynamic languages such as C, C++, and Java. C is a flexible and powerful language but is comparatively low level and can be challenging to learn. C++ significantly extends C but offers a cornucopia of language features that, if not used correctly, allow you to “shoot yourself in the foot” (the ability to redefine operators like “+” is one example). Java has fewer sharp edges than C++ but is more verbose than C and less flexible than dynamic languages.
As we mentioned earlier, Node breaks from tradition and leverages JavaScript, which makes it accessible to a large number of programmers. Given JavaScript’s strengths, if Node is widely adopted by server developers, the result will likely be quicker application development and increased diversity in server software.
Node versions of a variety of traditional server applications have already been written. Node-based DNS servers, web crawlers, message queue servers, and many other types of applications exist.
Node is also useful for exploring and implementing TCP/IP protocols. A recent example of improving the Web with new protocols is the WebSocket protocol. The Web’s first real-time applications used AJAX to exchange messages with the web server. AJAX uses HTTP as a transport mechanism to send messages back and forth to the server. Because HTTP requires a lot of communication overhead, AJAX’s performance is limited and both server and client have to do extra work. WebSocket was created in 2010 to provide an alternative: a lightweight, bidirectional protocol specifically focused on real-time textual communication.
The popular Socket.io project, which implements a robust Node-driven WebSocket server, is a good example of Node being used for protocol development.

JavaScript is excellent for specifying asynchronous logic because functions are “first-class objects.” This means the language allows functions themselves to be passed as function arguments, used as return values, and assigned to variables.
Callback functions are used to specify asynchronous logic. A callback is a function argument that contains a reference to program logic. Callbacks indicate an action to take when a programming event occurs or after intermediary logic is completed. JavaScript’s callback syntax is very elegant: either a function name or syntax- defining function logic can be passed as a callback.
JavaScript also has the advantage of being portable between the browser and the server. As long as any APIs accessed by logic are available on both the browser and the server, the same logic should run in either environment. Form validation, for example, is often duplicated on the client and the server. Why write the same code twice? Reusing logic on both the browser and the server enforces consistency and means not having to reinvent the wheel. It also means you have to maintain less code. Another benefit is you don’t have to mentally context-switch between languages when working on different parts of a web application. Staying in one language is likely to increase your productivity and make development more enjoyable.
Web applications are just the beginning
Node can develop much more than web applications. Node is also a good fit for designing servers, protocols, and command-line applications.
Server applications such as file transfer, email delivery, and instant messaging applications have traditionally been created in non-dynamic languages such as C, C++, and Java. C is a flexible and powerful language but is comparatively low level and can be challenging to learn. C++ significantly extends C but offers a cornucopia of language features that, if not used correctly, allow you to “shoot yourself in the foot” (the ability to redefine operators like “+” is one example). Java has fewer sharp edges than C++ but is more verbose than C and less flexible than dynamic languages.
As we mentioned earlier, Node breaks from tradition and leverages JavaScript, which makes it accessible to a large number of programmers. Given JavaScript’s strengths, if Node is widely adopted by server developers, the result will likely be quicker application development and increased diversity in server software.
Node versions of a variety of traditional server applications have already been written. Node-based DNS servers, web crawlers, message queue servers, and many other types of applications exist.
Node is also useful for exploring and implementing TCP/IP protocols. A recent example of improving the Web with new protocols is the WebSocket protocol. The Web’s first real-time applications used AJAX to exchange messages with the web server. AJAX uses HTTP as a transport mechanism to send messages back and forth to the server. Because HTTP requires a lot of communication overhead, AJAX’s performance is limited and both server and client have to do extra work. WebSocket was created in 2010 to provide an alternative: a lightweight, bidirectional protocol specifically focused on real-time textual communication.
The popular Socket.io project, which implements a robust Node-driven WebSocket server, is a good example of Node being used for protocol development.
The things that make Node perfect for server development also make Node a great candidate for the development of command-line interface (CLI) applications. Examples of common CLI applications include version control applications, database clients, and compilers. In addition to its networking API, Node offers access to functionality commonly needed by CLI applications: filesystem, process, and operating system functionality.
The Node community has created modules that make CLI application development easy by elegantly handling option and command parsing. The combination of the familiar JavaScript language with Node’s elegant APIs and easy CLI parsing has the potential to unleash the creativity of many who have, until now, only dabbled in CLI application creation.
Node can pretend to be a browser
Because Node is programmed in JavaScript, the language of the Web, another useful thing that Node can do more easily than other web frameworks is emulate web browser functionality. Emulating a web browser is useful for “web scraping” (parsing HTML from files or websites) and automated web application testing.
JSDOM, a Node community add-on, allows Node to emulate the web browser’s Document Object Model (DOM). The DOM is essential for web browser emulation, acting as a JavaScript-accessible interface to HTML/CSS content. By emulating the DOM, Node can read and write HTML in a virtual browser. Node can then take advantage of high- level JavaScript libraries, like JQuery, that allow high-level manipulation of the DOM.
Summary
We think any web developer who spends the time to explore Node is going to end up thinking of web development in a new way and will greatly enjoy themselves in the process.
The Node community has created modules that make CLI application development easy by elegantly handling option and command parsing. The combination of the familiar JavaScript language with Node’s elegant APIs and easy CLI parsing has the potential to unleash the creativity of many who have, until now, only dabbled in CLI application creation.
Node can pretend to be a browser
Because Node is programmed in JavaScript, the language of the Web, another useful thing that Node can do more easily than other web frameworks is emulate web browser functionality. Emulating a web browser is useful for “web scraping” (parsing HTML from files or websites) and automated web application testing.
JSDOM, a Node community add-on, allows Node to emulate the web browser’s Document Object Model (DOM). The DOM is essential for web browser emulation, acting as a JavaScript-accessible interface to HTML/CSS content. By emulating the DOM, Node can read and write HTML in a virtual browser. Node can then take advantage of high- level JavaScript libraries, like JQuery, that allow high-level manipulation of the DOM.
Summary
We think any web developer who spends the time to explore Node is going to end up thinking of web development in a new way and will greatly enjoy themselves in the process.
No comments:
Post a Comment