Strack | Meteor Cookbook | E-Book | www.sack.de
E-Book

E-Book, Englisch, 364 Seiten

Strack Meteor Cookbook

Build elegant full-stack web applications with Meteor, the JavaScript framework that's redefining web development
1. Auflage 2025
ISBN: 978-1-78328-030-8
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)

Build elegant full-stack web applications with Meteor, the JavaScript framework that's redefining web development

E-Book, Englisch, 364 Seiten

ISBN: 978-1-78328-030-8
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)



This book is meant for developers of all experience levels looking to create mobile and full-stack web applications in JavaScript. Many of the simple recipes can easily be followed by less-experienced developers, while some of the advanced recipes will require extensive knowledge of existing web, mobile, and server technologies. Any application or enterprise web developer looking to create full-stack JavaScript-based apps will benefit from the recipes and concepts covered in this book.

Strack Meteor Cookbook jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


Deploying to a custom hosted environment


When you are ready to actually deploy your app to a production environment, you will need to convert your Meteor application to a straight up Node application. There are multiple methods to do this, all of which are (currently) manual processes and not for the beginner. A lot can go wrong. This recipe will show you how to manually deploy your Meteor application to a production server as a Node application.

Getting ready


As mentioned, there are multiple methods and server configurations that can successfully host a Node application. There are, however, some commonalities, all of which you will need for this recipe.

First, you will need a hosted MongoDB database.

Your MongoDB database can be hosted remotely or on the same machine from where you will deploy your Node application. For this recipe, we have deployed a default MongoDB database to the same machine where we will host the app. Our value will therefore be:

MONGO_URL=mongodb://localhost:27017

Tip


Installation instructions (and tutorials) for MongoDB can be found at http://docs.mongodb.org/manual/installation/.

Free or cheap but dedicated MongoDB service hosting also exists. Run a quick Internet search for or visit http://www.mongodb.com/partners/cloud for a list of providers.

Next, your hosting environment will need the latest stable Node and npm modules.

Installation instructions for each of these programs are beyond the scope of this book. For installation instructions and advice on how to get started, visit the following:

Tip


The latest or nightly builds of these programs will likely cause you problems in a production environment. Be sure to use the stable versions, unless you have thoroughly tested a different version.

Lastly, you will need the npm module installed in your hosting environment. From a terminal window on your hosted environment, run the following command:

$ npm install –g forever

Note that you may need to use the command to install the package globally. This will depend on how npm was installed on your server. The preceding command will install on your machine, and you are now ready to prepare and deploy your application to production.

How to do it…


To deploy to a custom hosted environment, proceed with the following steps:

  1. Open a terminal window in your development environment and navigate to the root folder of your Meteor project. In this root folder, execute the following command:
    $ meteor build [your-build-location] --architecture [x]

    Replace the placeholders in the preceding line of code with your build location (for example: ) and an architecture (the options are , , and ). The option is optional if you are building this on the same server where you will deploy your app.

  2. Meteor will bundle, extract, and repackage a clean production copy of your Meteor project, preparing it to be used in your hosting environment. While it is being built, Meteor will update you with the status in the terminal window.
  3. Once the build is finished, navigate to the build folder you specified, for example, if you specified as your build location, you would need to enter the following command:
    $ cd ~/Documents/builds/mybuild
  4. In the build folder, you will see a file with a name similar to .

    So, for example, if the name of my project was , the name of the file would be .

  5. Make a note of the name and location because you'll need it when you copy and extract the build to your server.
  6. For this recipe, let's assume you're using a Linux server to host your production application. Let's create a folder using the following terminal command:
    $ mkdir /home/meteorapps
  7. Next, copy the file from your development environment to the folder in your production-hosted environment.

    If you build your application on a different machine, you can transfer it via SCP, FTP, a common file server, a Git repository, and so on. It really doesn't matter how you copy it over, as long as a copy of the file is now in your hosted environment.

  8. Once it's copied over, run the following command on the file:
    $ tar –xf [your-tarball-name].tar.gz

    This will extract the file to a folder named . If you navigate to the folder, you will find a file. The next steps in this recipe are taken from this file, so feel free to check them out for a more concise set of instructions. If you check the contents of the folder, you should see something similar to the following:

    README main.js programs server star.json
  9. We will now install the npm packages needed to run our application. Navigate to and execute the following command:
    $ npm install

    Note


    Note that we did not use the argument, as we are only installing the local npm packages specified in the bundled folder.

  10. Next, we will need to set the and export arguments so that Node knows how to host our application. Enter the following commands in the terminal window:
    $ export PORT=8080 $ export MONGO_URL=mongodb://localhost:27017

    These two export commands tell your Node server what port to listen on, and where to find the hosted instance (we're using a local instance in this example).

    You will also want to configure the and environment variables. The syntax to enter them is similar to the following export commands:

    $ export ROOT_URL='http://[your-hostname.com]' $ export MAIL_URL='smtp://user:password@mailhost:port/'

Now, we can run our application. Instead of using the default command, remember that we installed the npm package. The package allows us to run our Node application and will automatically restart it if we encounter an error. Run the following command in the terminal window:

$ forever start main.js

This command instructs Node to start as a node application, and to restart it if there are any issues.

Tip


You can stop the application later on by issuing the following command from the directory:

$ forever stop main.js

Now it's time to test whether your application is successfully running by opening a browser and pointing it to your host environment, on the port you specified, for example, if our production environment was hosting the subdomain, and we specify , as shown in the preceding example, we would navigate to in a browser.

Your app should be up and serving pages.

How it works…


Node is built to run as quickly as possible. To do so, it will run a little differently on different hardware and software configurations. This means that the Node and npm packages you use in your development environment (for example, on MAC OS X) are slightly different than the corresponding Node and npm packages in your production environment (for example, Linux Ubuntu 12.4 LTS Precise). This is especially true for foundational packages, such as the npm fibers package.

Also, although Meteor is built on top of Node, it isn't a native Node application. There are some additional layers of abstraction and processing that make your life easier as a developer, but they don't make for the prettiest native Node production environment.

The command takes care of this for us and creates a build without the npm packages installed. Instead, it lists any of the npm packages as dependencies. Because the specific npm packages aren't included (Meteor listed them in a package manifest file instead), there are no compatibility issues. We simply tell Node to find and install the packages specific to the current environment, using the package manifest file as a sort of a laundry list. We did this when we issued the command.

Once npm has read the manifest file, retrieved and installed all the needed packages, and informed us that the...



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.