Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Mastering Node.js

You're reading from   Mastering Node.js Expert techniques for building fast servers and scalable, real-time network applications with minimal effort

Arrow left icon
Product type Paperback
Published in Nov 2013
Publisher Packt
ISBN-13 9781782166320
Length 346 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sandro Pasquali Sandro Pasquali
Author Profile Icon Sandro Pasquali
Sandro Pasquali
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Mastering Node.js
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
1. Understanding the Node Environment FREE CHAPTER 2. Understanding Asynchronous Event-Driven Programming 3. Streaming Data Across Nodes and Clients 4. Using Node to Access the Filesystem 5. Managing Many Simultaneous Client Connections 6. Creating Real-time Applications 7. Utilizing Multiple Processes 8. Scaling Your Application 9. Testing your Application Organizing Your Work Introducing the Path Framework Creating your own C++ Add-ons Index

Appendix C. Creating your own C++ Add-ons

 

"If two (people) on the same job agree all the time then one is useless. If they disagree all the time, then both are useless."

 
 --Darryl F. Zanuck

A very common description of Node is this: Node.js allows JavaScript to run on the server. While true, this is also misleading. Node's creators organized and linked powerful C++ libraries in such a way that their efficiency could be harnessed without developers needing to comprehend their complexities. Node abstracts away the complexity of multiuser, simultaneous multithreaded I/O by wrapping that concurrency model into a single-threaded environment that is easy to understand and already well understood by millions of web developers.

When you are working with Node you are ultimately working with C++, a language whose suitability for enterprise-level software development no one would question.

Node's C++ foundation puts lie to claims that Node is not enterprise-ready. These claims confuse what JavaScript's role in the Node stack actually is. The bindings to Redis and other database drivers used regularly in Node programs are C bindings–fast, near the "metal". Node's process bindings (spawn, exec, and so on) facilitate a smooth integration of powerful system libraries (such as ImageMagick) with headless browsers and HTTP data streams. With Node, we are able to access the enormously powerful suite of native Unix programs through the ease and comfort of JavaScript. And of course, we can write our own C++ add-ons.

Paraphrasing Professor Keith Devlin's description in Calculus: One of the Most Successful Technologies (https://www.youtube.com/watch?v=8ZLC0egL6pc), these are some features of successful consumer technologies:

  • It should remove difficulty or drudgery from the process of completing a task.

  • It should be easy to learn and use.

  • It should be easier to learn and use than the popular method, if one exists.

  • Once learned, it can be used without constant expert guidance. A user remains able to remember and/or derive most or all of the rules governing interactions with the technology through time.

  • It should be possible to use it without knowing how it works.

Hopefully, as you think about the class of problems Node aims to solve, and the form of the solution it provides, the above five features are easily seen in the technology Node represents. Node is fun to learn and use, with a consistent and predictable interface. Importantly, "under the hood" Node runs enormously powerful tools that the developer only needs to understand in terms of their API.

Wonderfully, Node, V8, libuv, and the other libraries composing the Node stack are open sourced, a significant fact that further distinguishes Node from many competitors. Not only can one contribute directly to the core libraries but one can cut and paste code blocks and other routines to use in one's own work. You should see your growth into a better Node developer as a chance to simultaneously become a better C++ programmer.

This is not a primer on C++, leaving you to pursue this study on your own. Don't be intimidated! The C-family of languages is designed using forms and idioms not unlike what you are already used to with JavaScript. For example, if..then constructs, for loops, functions, and returning values from functions, even semicolon-terminated lines, are central to JavaScript and regularly used in C++ programming. As a JavaScript developer you should be able to understand the design and goals of the following examples with little effort, and can dip into C++ programming to resolve the meaning of the parts that aren't clear. Extending these examples iteratively is an excellent way to gently enter the world of C++ programming.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images