Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MeteorJS: Introduction and Setup

DZone's Guide to

MeteorJS: Introduction and Setup

Here is a short intro to MeteorJS and how to set it up.

· Web Dev Zone
Free Resource

Add user login and MFA to your next project in minutes. Create a free Okta developer account, drop in one of our SDKs to your application and get back to building.

What Is MeteorJS?

MeteorJS is a javascript framework to create web applications. It is built on the top of NodeJS and uses MongoDB as a storage layer.

Components of Meteor

There are 5 major components on which MeteorJS is built upon.

BlazeUI

This library of MeteorJS is helpful to give live updates to user. This library is responsible for updating DOM. It is just like AngularJS where in DOM you have to just tell what you want and if there is any update then it will take care of that.

MongoDB

Meteor project comes with MongoDB, without writing any configuration file. It can be accessed from remote by adding 2 in the Meteor server port. For instance, if Meteor is running at 3000 then MongoDB will run at 3002 port. The MongoDB files are in .meteor directory of Meteor project.

DDP

Distributed Data Protocol(DDP), is a communication layer between client and server. It is based on web sockets. Everything that happens between client and server is only through DDP. Client and server do not know each other. It is not mandatory that client and server both should be of Meteor. Meteor client can talk to other servers who understand DDP and Meteor server can talk to other clients who understand DDP.

Live Query

It is a communication layer between and server and database. It continuously listens to database and sends updates to the server if anything happens in the database. So if anything happens in the database then without hitting the refresh button you will get updated results on the screen. In general, it requires a separate implementation for each database.

Benefits of Meteor

  1. You can get real-time updates without writing an extra code for it.

  2. Packaging system – You can save lots of time by using MeteorJS packages. There are many built-in packages that can be used as it is. Using packages and writing your package for others is also very easy. Rails developers can think of gem as a package.

  3. Learning curve is low. You need to have command over javascript because MeteorJS uses javascript on both client and server side.

  4. Meteor itself minified the javascript and css in production mode.

  5. Meteor automatically syncs the state between client and server.

  6. The community of Meteor is very active and supportive.

An Example

Below are the few commands that will install MeteorJS and then it will create the project for authentication.

Installation

$ curl https://install.meteor.com/ | sh

To create an application with name authentication

         meteor create authentication

The output of above command will be the following.

Run Application

Go to authentication directory – cd authentication and you will see project structure like this:

  1. Type command – meteor 

  2. Open the browser and go to http://localhost:3000  

  3. By executing above commands you will see something like this-

Add package

          meteor add accounts-base

          meteor add accounts-password

          meteor add accounts-ui

The above 3 commands will add authentication packages.

  1. Display buttons on UI

  2. Add below line in authentication.html and comment  {{> hello}}  line

    1.  {{> loginButtons}} 

The above line will give you ‘Sign in’ link on your browser and when you click on that link you will get ‘Sign in Form’ and other links that are required for authentication

So the above commands will create a fully working authentication app.

Now it’s your time to play with Meteor.

Launch your application faster with Okta’s user management API. Register today for the free forever developer edition!

Topics:
javascript ,mongo db ,meteor.js ,web dev

Published at DZone with permission of Shanky Munjal. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}