Real-time web applications with the Meteor framework
Shooting Star
The Meteor web framework lets you do all your programming in JavaScript – and it includes some useful features for rapid development.
Many web developers use multiple programming languages for a single application: code in PHP, Ruby, Python, or Java on the server and JavaScript for the browser. Thanks to the open source Meteor [1] framework, developers can now program web applications entirely in JavaScript, with just the normal dusting of HTML and CSS. Programming in one language can significantly reduce the development overhead. Meteor also offers some automation features and a variety of prebuilt packages.
In this article, I show how to implement an interactive web application with Meteor, JavaScript, HTML5, and CSS3. As an example, I'll show you how to create a simple content management system with a list of contributions, an editor, and access controls.
Installation
Meteor is released under the MIT license and was available in a prerelease version numbered 0.7.0 when this issue went to press. When version 1.0 of the framework appears in the spring of 2014, Meteor will be ready for production. Meteor itself is written entirely in JavaScript. On the server side, Meteor relies on Node.js. The Meteor Development Group developed the Meteor software as an open source project, which was sponsored by several investors from the Internet industry.
Listing 1 installs Meteor on Ubuntu 12.04 in the user's home directory; it then generates the skeleton of the example application called Starpublisher. Line 1 first uses Apt to fetch the Curl command-line tool. Line 2 uses the tool to download the current Meteor distribution and install. Line 3 creates the Starpublisher project; line 4 changes to the project directory, and line 5 starts the sample application. Detailed documentation of Meteor is available online [2].
Listing 1
Installation
Development Sequences
A Meteor application runs immediately after you create the basic framework. Figure 1 shows Starpublisher in the Firefox browser. By default, Meteor applications are accessible via HTTP on port 3000. The developer installs the required Meteor packages in the project directory and programs the application logic.
Meteor supports the programmer in many ways. For example, after each change, the framework restarts the web server in the project directory and automatically refreshes the browser view. Figure 2 shows Meteor's output in the terminal emulator. Meteor reports reboots here and encourages the application developer to fix bugs.
The web framework only processes program code in JavaScript. On the server, the web server supplied with the distribution, Node.js, is responsible for this processing [3], whereas the browser uses its own JavaScript engine. Meteor picks the JavaScript code from the project directory itself.
Figure 3 shows the assignment of JavaScript files for server-side (s) or client-side (c) execution in the directory tree of a project directory. The numbers indicate the order for automatic loading. JavaScript files from the directory server
are only run on the web server, whereas those in client
are only run in the browser. All others run in/on both, except for the public
folder (for images and static files) and the private
folder (files that the server, but not the browser, is permitted to read).
Additionally, the two Boolean properties (Meteor.isServer
and Meteor.isClient
) in Listing 2 let developers restrict the execution of JavaScript code to the web server or the browser. In the example, taken from main.js
in the project
directory in Figure 3, line 1 is executed by the web server and the browser, line 3 only by the web server, and line 5 only by the JavaScript engine in the browser.
Listing 2
Context-Specific Execution
Data Management
Meteor stores the application data in the form of JavaScript objects; the free NoSQL database system MongoDB ensures persistence. The database server is included with the Meteor distribution and does not need to be installed separately. In the browser, Meteor has access to a constantly updated copy of the data held by MongoDB. Listing 3 shows the process of storing a JavaScript object in the Articles
data collection below Meteor
. Line 1 opens the Articles
data collection, thus instantiating a Collection
type object. Line 2 saves the empty object, {}
, in Articles
by calling the insert()
method.
Listing 3
Access via the Collection API
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.