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
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.