Chapter 10. Advanced server methods

 

This chapter covers

  • Understanding the difference between synchronous and asynchronous functions
  • Using asynchronous functions
  • Integrating external APIs
  • Uploading files

Even though Meteor is an isomorphic platform, some things can only be done in certain environments. This chapter introduces you to some advanced concepts on the server. With Node.js running in the background, it’s time to take a closer look at the event loop and the right way to work with asynchronous code. This is especially useful if you plan to have your application communicate with external APIs.

While we’re looking into server specifics, we’ll also discuss a simple way to upload files to the server. The code in this chapter should run on the server unless stated otherwise.

10.1. Reintroducing Node.js

The foundation of the Meteor stack is Node.js (see figure 10.1). Technically, it’s a server implementation of the V8 JavaScript engine that can also be found in the Google Chrome browser. Therefore, it comes as no surprise that Node.js shows the same characteristics as a browser. It’s because of two reasons:

Figure 10.1. Node.js is the server engine for all Meteor applications.
  • Node.js is event driven.
  • Node.js uses nonblocking I/O.

These two characteristics make Node.js stand out from other server technology such as PHP or Rails that typically execute code in a linear or synchronous way. But even if Node.js is by nature nonblocking, you can still write blocking code.

10.2. Asynchronous functions using fibers

 
 
 

10.3. Integrating external APIs

 

10.4. Uploading files to a collection

 
 
 

10.5. Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest