Advanced JavaScript: Environment Setup, DB integration and Securing Client in MeteorJS

This tutorial is in continuation with previous tutorial. If you are new here, read first chapter of this series Advanced JavaScript: Introduction To Server Side JavaScript Using Meteor before reading this tutorial.

I will be skipping traditional TO DO app tutorial here, as you can find it anywhere on web. Rather, I will try to explain few scenarios that developers come across while developing apps using JavaScript frameworks in real-time.

In this tutorial we will be covering

  • Setting up development environment for Meteor?
  • How to integrate your Meteor application with Mongo DB?
  • How to secure your Meteor application?

Setting up development environment for Meteor
Most popular IDEs like Sublime, Webstorm and on-cloud IDE- Cloud 9 integrates seamlessly with Meteor. I am a fan of Sublime so I will explain how to set up autocomplete engine into Sublime Text 3. You can visit Meteor website and setup your own IDE.
Open Sublime Text-

  1. From menu bar select preferences-> Settings -Users
  2. If you have not made any changes from time you installed Sublime replace contents of file with following code-
  3. {
    	"color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
    	"font_size": 12,
    	"auto_complete_triggers": [ { "characters": "<", "selector": "text.html" }, { "characters": ".", "selector": "source.js" } ]
  4. Now press Cmd/Ctrl+Shift+P and type Install. You will see ‘Package Control: Install Package’ in menu. Select it and press Enter. Now search for TernJS and click on it. Package will install automatically. Restart Sublime and you will see your Sublime just got smarter and it can autocomplete Meteor code for you.


How to integrate your Meteor application with Mongo DB?
We already have Meteor code running on local server. Now let’s add DB support. Meteor comes bundled with MongoDB so you don’t need to include it again, still if you wish you can do custom setup but let’s not discuss it in this tutorial as pre bundle itself is self-sufficient to create end-end application.

  1. Lets create Fishes collection.
    Fishes = new Mongo.Collection("fishes");

    It creates a MongoDB collection called Fishes and creates a cache connected to server.

  2. Replace if (Meteor.isClient) with this code
    if (Meteor.isClient) {
      // This code only runs on the client
        fishes: function () {
          return Fishes.find({});
  3. From terminal type
    meteor mongo
  4. meteor-mongo-terminal

  5. Now write this insert query to add a new fish

    db.fishes.insert({ text: "pygmy angelfish",imageurl:"", createdAt: new Date() });
  6. check-db-for-fishes

  7. Now go to http://localhost:3000 and check if you are can see live fish coming from live data. If yes, you just added DB connectivity to your meteor application.

Now add some more blue fishes to grow your list-

db.fishes.insert({ text: "pygmy angelfish",imageurl:"", createdAt: new Date() });
db.fishes.insert({ text: "blue dot grouper",imageurl:"", createdAt: new Date() });
db.fishes.insert({ text: "blue line grouper",imageurl:"", createdAt: new Date() });
db.fishes.insert({ text: "teira batfish",imageurl:"", createdAt: new Date() });
db.fishes.insert({ text: "convict blenny",imageurl:"", createdAt: new Date() });

How to secure your application?
One of main concern while using JavaScript for both server and client side code is security. Try running following code from console:

Fishes.insert({ text: "Fighter",imageurl:"", createdAt: new Date() });

From MongoDB console run


and you will see both client and server have a new beautiful red fighter fish. If you noticed, you were able to alter DB using Javascript without authenticating with server which is a security breach. This is beacause Meteor has insecure package selected by default.

  1. To remove insecure package navigate to your project folder in Command Line /Terminal and run-
  2. meteor remove insecure


  3. Now enable the accounts system and UI using following command from root directory of project-
  4. meteor add accounts-ui accounts-password

    I find package control really useful. They make your life lot easier by taking care of entire setup for useful technical modules, as in this example entire user management. Few years back implementing secured login module was estimated around 100 hours which came down to 1 minute with recent advancement in web technologies.

  5. Now add login buttons to your app. Paste following blaze template anywhere in code. I will paste it in header.
  6. {{> loginButtons}}
  7. Now signup for new account and run this command from console-
  8. if (! Meteor.userId()) {
          throw new Meteor.Error("not-authorized");
    Fishes.insert({ text: "Fighter",imageurl:"", createdAt: new Date() });


    You will notice you are not able to insert data any more. Meteor.user() will return user data to you.

We will discuss security, Blaze templates and routing in detail in next chapter of this tutorial. Till then Happy Coding!

Now you can follow this tutorial on GitHub.


Images credits-


Advanced Javascript: Introduction To Server Side Javascript Using Meteor

Server Side Javascript has come long way, and after launch of Node.js in July 2011 gained lot of popularity as idea of using same language on client and server bought in code and software architecture uniformity in software applications. Even though Brendan Neich‘s Netscape already had vision to use same programming language on client and server but at that time people were using Pentium I/II processors which were not powerful enough to support Javascript Interpreters. In case you don’t know Brendan Neich he’s creator of Javascript and co-founder of Mozilla. In present generation of more than 2 billion smartphones you can get Phone with 1.2 GHz processor for less than $40. Seeing boom in processing speed of devices software developers started integrating Javascript interpreters like SpiderMonkey & Rhino in their applications. Some started using Jaxter server that embeds entire Mozilla Firefox Browser Engine in web server giving access to Ajax and Javascript within application.

Now when we have brief history of Javascript let me explain how to setup Meteor and create a simple server side Javascript application.

Go to this link and install Meteor.

Once you are done with setup go to command like and create a directory named bluefish if you would like to follow remaining series of tutorial.

Nikhils-MacBook-Pro:bluefish nikhil$ meteor create bluefish
Created a new Meteor app in 'bluefish'.
Nikhils-MacBook-Pro:bluefish nikhil$ cd bluefish/
Nikhils-MacBook-Pro:bluefish nikhil$ meteor
Started proxy.
Started MongoDB.
Started your app.  
App running at: http://localhost:3000/

Screen Shot 2015-10-24 at 4.10.07 pm Screen Shot 2015-10-24 at 4.16.08 pm

Now navigate to http://localhost:3000/ and if everything if fine you will see following webpage-
Screen Shot 2015-10-24 at 5.07.16 pm

Now you can use your favourite code editor to change HTML and CSS and see if changes are getting reflected in your application without refreshing browser. If you can see updated HTML in your browser, congrats you deployed your first Javacsript Server Side Application. It’s called hot code push.

Now lets dig in a little and make our first bluefish list.

Edit your HTML and change it to

  <div class="container">
      {{#each fishes}}
        {{> fish}}
<template name="fish">
  <li><img src={{imageurl}} height="80" width="100"/>{{text}}</li>


Change your Javascript to

if (Meteor.isClient) {
  // This code only runs on the client
    fishes: [
      { text: "pygmy angelfish",imageurl:"" },
      { text: "blue dot grouper",imageurl:"" },
      { text: "blue line grouper",imageurl:"" },
      {text:  "teira batfish",imageurl:""},
      {text:  "convict blenny",imageurl:""}

You can write your custom styling in CSS file.

Screen Shot 2015-10-24 at 5.02.14 pm

For further information, visit or wait for next chapter of tutorial. Happy coding!

Image credits-


Stop Workplace Harassment in India

6 of 8 people in India go through workplace harassment without knowing they are being harassed. Wanted to share this important piece of advice for wellbeing of employees as well as employers.

To employers- you don’t owe your employees, they just work for money and cause they trust in you.

To employees- Know your rights, be aware. Even if you make mistakes no employer/boss has right to harass you.

Labour inspector from the Labour Department are employed for the well-being of the employee issues and there is no fee as such. Following are some common example of workplace harassment:

  • Dispersion of malevolent and untrue rumours, scandal or innuendo at the workplace. Isolating an individual socially and professionally in the office.
  • Threatening a person or dominating him/her unfairly.
  • Deliberately discouraging one or hindering his/her job.
  • Physical abuse or intimidating someone with abusive languages.
  • Eliminating one from his roles and responsibilities without any reason.
  • Altering instructions and guidelines constantly.
  • Imposing unrealistic deadlines intentionally to make an individual fail.
  • Holding back important information or tenaciously providing wrong information.
  • Cracking offensive jokes verbally or in written, especially in front of or about female colleagues.
  • Sneaking into someone’s personal life, spying or pestering him/her.
  • Causing unnecessary pressure on a particular person by assigning heavy workload when others are free.
  • Making on sit idle without any work which is also a way to create mental pressure on a worker. Often companies take this way to make their employees surrender for voluntary retirement schemes.
  • Screaming or showing vulgarity to an employee.
  • Intentionally and unreasonably criticizing an individual on regular basis.
  • Ridiculing one’s opinions. Unjustifiable punishment for trifles.
  • Holding back deserved leaves, promotions and training.
  • Blocking applications for training, leave or promotion.
  • Meddling with one’s personal belongings behind his/her back.

When any of the above happens to an individual, it indicates that he/she is falling prey to employee harassment. Be it the employer or co-workers, there are legal terms via which the offenders can be punished.

Indian constitution guarantees gender, racial and religious equality as the Fundamental Right’ of the residents of the country in Part III, Articles- 14, 15, 16 which implies for the workplace as well. Hence one faces discrimination by the employer because of his/her race, complexion, gender, caste or origin; he/she can immediately seek legal advice by consulting with a lawyer.  The ‘Directive Principles of State Policies’ of Part IV encompasses the cultural and socio-economic rights of Indian citizens.

Image credits-

Featured Image -- 1181

Apple Finally Fixes The iPhone Keyboard’s Worst Flaw In iOS 9


Now type what you see on iOS keyboard

Originally posted on TechCrunch:


It’s the little things in life.

Like, you know, being able to tell if your keyboard is currently set to use capital letters or not.

With iOS 9, Apple is finally fixing one of the platform’s strangest quirks: the keyboard will no longer appear to be all caps, all the time.


If you’re an Android user, or someone who just doesn’t think about stuff like this all that much, you might have no idea what I’m talking about.

You see, in all builds of iOS thus far, the keyboard always uses capital letters to represent each key — whether or not you’ve actually hit shift or have caps lock on.

That works well enough on physical keyboards — for the most part, you’re holding the shift key when you want shift turned on.

On a touchscreen keyboard, where you tap shift instead of hold, it’s not so simple. Sometimes you…

View original 109 more words

Featured Image -- 1157

Tencent Backs Mobile Gaming Company Pocket Gems

Originally posted on TechCrunch:

Pocket Gems announced today that it has taken an investment from Chinese Internet company Tencent. The funding will allow the mobile gaming company to expand globally, including into China.

The companies did not disclose the size of the deal, but The Wall Street Journal reported that Tencent invested $60 million for a 20 percent stake in Pocket Gems.

Pocket Gems recently launched its War Dragons title aimed at hardcore gamers. It says its games have seen more than 200 million downloads total.

“We’re thrilled to be partnering with Tencent, whose unparalleled strength in games publishing and operations in China will help us create great mobile games and entertainment for players globally,” said Pocket Gems CEO Ben Liu in the funding release.

View original

Featured Image -- 1159

WaitChatter Helps You Learn A New Language While You Wait For IM Replies

Originally posted on TechCrunch:

Despite the pace of online communications, we still spend a lot of time waiting: staring at an IM window is a common occurrence for anyone who spends a better part of their day at a computer. WaitChatter wants to make use of that standby time to promote a vital skill, letting users brush up on their vocabulary for a second language while they wait for their colleague or friend to respond to their Google Chat message.

The app comes out of research from MIT’s Computer Science and Artificial Intelligence Lab, which found that the average person racks up 10 to 15 minutes per day of essentially wasted waiting time while conversing over IM. That realization led to the development of WaitChatter, which uses a Google Chat (you have to revert from Hangouts to use it right now, but that’s fairly easy) extension to offer up quick vocabulary learning lessons right…

View original 175 more words