Preface

Modern web applications represent the new way to write software. Facebook, Twitter, and Wikipedia are some well-known examples of such applications. They run on servers, and users can access them with a browser via either desktop or mobile devices. We refer to these as “modern” applications because they combine a rich user interface with real-time interaction and the capability to connect with online services, among other capabilities.

Opa is a programming framework for JavaScript that enables you to easily write modern web applications that have all the aforementioned cool features. This book is a gentle introduction to Opa.

What Is Opa?

Traditionally, many different technologies and languages are involved when writing web applications. Not so with Opa! Opa is the only technology you need to know to write the code that runs on the client (in the browser) and the code that runs on the server, including database queries.

Opa natively supports the web platform, which is a set of technologies that includes HTML5 and CSS, and it automates many aspects of modern web application programming: Ajax/Comet client/server communication, event-driven and nonblocking code transformations, etc.

One of the main distinctive features of Opa is strong static typing, with type inference. This means that every application you write is checked by a program called a typechecker that automatically tracks inconsistencies in the application. Typing enables Opa programmers to debug applications quickly, and increases application safety and security.

As a final step, Opa generates standard code: JavaScript for the client side, Node.js, and MongoDB for the server side.

The philosophy of Opa is to support multiple platforms. It is possible to extend Opa to support different backends.

How Do I Work with Opa?

Working with Opa is as easy as 1, 2, 3:

  1. Write your application code in a text editor.
  2. Generate your application by invoking Opa.
  3. Run and/or deploy your application online.

In Installing Opa, you will learn how to install Opa and create your first application. Then you will develop two real applications with Opa: a mini-Wikipedia and a mini-Twitter.

The applications you develop with Opa are standard JavaScript projects that run both in the browser (where JavaScript is by far the most prevalent) and on the server. On the server side (also called the backend), the applications rely on two popular technologies for the runtime:

  • Node.js, which allows you to execute JavaScript code on the server
  • MongoDB, which is a NoSQL database server

Both technologies were chosen for their ability to scale, that is, easily add servers to handle more clients when your application becomes hugely popular.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords
Constant width bold
Shows commands or other text that should be typed literally by the user
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, if this book includes code examples, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Opa: Up and Running by Henri Binsztok, Adam Koprowski, and Ida Swarczewskaja (O’Reilly). Copyright 2013 MLstate, 978-1-449-32885-6.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://oreil.ly/Opa_1E.

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

The authors would like to thank Alok Menghrajani, who did a thorough review of the original draft of the book. Opa would never exist without the work of its contributors, including the core developers of Opa: Cédric Soulas, Frédéric Ye, Norman Scaife, and Quentin Bourgerie. Thank you for your impressive work.

Get Opa: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.