In a previous how-to, we created a RESTful API to search videos, performing the actual search through YouTube Data API. To provide additional support for languages and to demonstrate that we are stating general principles that can be implemented using (almost) any programming language/technology, in this report we will explain how to implement the same interface using node.js. As you’ll see, using a couple of Node modules, the job is even easier than with Google App Engine.

Here is a list of features we will implement:

We’ll need to route three different paths, as we did with our Python implementation for Google App Engine. However, while the Python implementation required that we get into the details of regular expressions to define the rules to match those paths, with the Express module for Node we will be able to effortlessly catch the parameters in the URLs.

Setting Up Node.js

If you have not already installed node.js on your machine, you can download the installer here. To test if Node is correctly installed, just type node in a terminal/console window, and you should be presented with a JavaScript console. (Try to type a few JS expressions, like 2 + 2 or “test”.toUpperCase(), to double-check.)

Now you can create a folder to contain your project. For example, I created one named “pweb.”

Enter your folder name, and create a new file named package.json. This configuration file will be needed if you export your module.