Chapter 1

Getting Started

古くから伝わるプログラミングに関する格言として次のようなものがあります。「機能は資産だが、コードは負債である。」

An old programming adage says that while functionality is an asset, code is a liability.

本書を通し Node.js の乗りこなし方を身につけるに当たって、次のことを念頭に置いてください。コードにおいて一番素晴らしい一行は、書く必要がないために書かなかった一行です。書かずに済むのなら、そうすべきです!

Throughout this book, as you learn to harness Node.js, keep in mind that the best line of code is the one you never had to write. If you can get something for free, take it!

とはいえ、技術書の宿命として、みなさんに何かしらを実行する方法を教えねばなりません。たとえ既に誰かが代わりにやってくれているようなことでもです。物事がどのように動いているのかを理解することで、その知識を土台としてさらにいい方法でやれるようになるからです。

However, the nature of a technical book is to teach you how to do something, even if somebody has already done it for you. By understanding how things work, you’ll be better able to build on top of them.

ですから、基礎的なところから始めて段階的に進んでいくことにしましょう。まずは Node.js の基盤に近いところから始めていきます。Node.js の環境、言語、原理的な API についてです。これらへ習熟するにつれて、他の人が書いてくれた module や、ライブラリ、サービスを使う方法を学んでいくことになります。それができるようになったら次のレベルに進みましょう。

So we’ll be progressing in stages. In the beginning, you’ll be working at the lowest levels of Node.js — getting to know the environment, the language, and the fundamental APIs. As you master those, you’ll learn how to use other peoples’ modules, libraries, and services to replace some of that code and go to the next level.

最終的には、最大の効果を得るために既存のライブラリを使用するほうがいい場合と、自分自身で機能を実装したほうがいい場合とを、判断できるようになります。結局のところ、この叡智が、新人開発者とあなたとを分ける力の源となるのです。

By the end, you’ll see where it’s possible to make great gains using existing libraries, and where it makes sense to implement the functionality yourself. At the end of the day, this wisdom is the power that will distinguish you from a novice developer.

Thinking Beyond the web

A lot of the buzz around Node.js is focused on the web. In truth, Node.js serves a bigger purpose that people often miss. Let’s use a map to see where Node.js fits in the broader scheme of things. Imagine the set of all possible programs as the inhabitants of a vast sea. Programs that have similar purposes are near each other, and programs that differ are further apart. With that picture in mind, take a look at this map. It shows a close-up of one particular outcrop in this sea, the Island of I/O-Bound Programs. I/O-bound programs are constrained by data access. These are programs where adding more processing power or RAM often makes little difference.