Chapter 5. Node.js and Regex

So far, we've had fun learning how to create regular expressions for different situations. However, you may be wondering what it would be like to apply a regular expression in a real-world situation, such as reading a log file and presenting its information in a user-friendlier format?

In this chapter, we will learn how to implement a simple Node.js application that reads a log file and parses it using a regular expression. This way, we can retrieve specific information from it and output it in a different format. We are going to test all the knowledge we obtained from the previous chapters of this book.

In this chapter we will cover the following topics:

  • Installing the required software to develop our example
  • Reading a file with Node.js
  • Analyzing the anatomy of an Apache log file
  • Creating a parse with regular expressions to read an Apache log file

Setting up Node.js

Since we will be developing a Node.js application, the first step is to have Node.js installed. We can get it from http://nodejs.org/download/. Just follow the download instructions and we will have it set up on our computer.

Note

If this is your first time working with Node.js, please go through the tutorials at https://nodejs.org/.

To make sure we have Node.js installed, open the terminal application (Command Prompt, if you're using Windows), and type node –v. The Node.js version installed should be displayed as follows:

Setting up Node.js

We are now good to go!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset