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
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.