Google News
logo
Meteor.js Interview Questions
Meteor provides its own server (free) to deploy and test your application with command "meteor deploy appname". If you want to deploy application on your own server and domain, you will need VPS (Virtual Private Server) or cloud hosting like Heroku or Modulus.
Tracker is a small library that is used for auto update templates once the session data has changed. Tracker.autorun() method is used for tracking on session.
var data = 0  
   Session.set('sessionData', data);  
   Tracker.autorun(function () {  
      var sessionValue = Session.get('sessionData');  
      console.log(sessionValue)  
   });  

   Template.myTemplate.events({  
      'click #myButton': function() {  
         Session.set('sessionData', data++);  
      }  
   });
Session is used to save data while app is in use. The session data will be deleted while user leaves the app. In Meteor session are created by using Session.set() method. Once the session data is set, it can return using Session.get() method.
Using Fibers we can modify an asynchronous function, to write synchronous like code.In Meteor server-side code, the first-class support means that Meteor Promises play nicely with Fibers/Futures, which makes it possible to mix the sync-style coding we’ve become used to with the more mainstream Promise-based coding.
Blaze is Meteor's built-in reactive rendering library for creating user interfaces by writing reactive HTML templates. It eliminates the need for all the “update logic” in your app that listens for data changes and manipulates the DOM.
Meteor 2.7 introduce the new accounts-2fa package, support for TailwindCSS 3.x, and built-in support for PostCSS in standard-minifier-css. 
 
The above being said, there are a few items that you should do to have the latest CSS minifier in your project.
 
Update meteor-node-stubs : As we added support for node: imports, you need to update meteor-node-stubs to version 1.2.1:
meteor npm install meteor-node-stubs@1.2.1
Support for PostCSS
Starting from this version of Meteor (and 1.8.0 of standard-minifier-css), Meteor will run PostCSS plugins if you have them configured. If you are using juliancwirko:postcss as your css minifier, it is recommended to migrate to using standard-minifier-css. For most apps, this will only requiring switching which minifier the app uses:
meteor remove juliancwirko:postcss
meteor add standard-minifier-css
There are two differences with juliancwirko:postcss :
 
* The excludedPackages PostCSS option was renamed to excludedMeteorPackages
* Files with the .import.css extension are not treated specially

Note : In beta.1 of Meteor 2.7 we had added a new core package minifier-css-postcss but later decided to unify everything inside standard-minifier-css. So you shouldn’t use minifier-css-postcss.
 
TailwindCSS 3.x : Improvements in Meteor 2.7 enables minifiers to support TailwindCSS 3.x. These minifiers have been updated and tested with TailwindCSS 3:
 
* juliancwirko:postcss, starting with version 2.1.0
* standard-minifier-css

If updating from an older version of TailwindCSS to version 3, please read the Tailwind Official migration guide to make sure you had applied the changes required by TailwindCSS itself.
 
Accounts 2FA : accounts-2fa is a new package that enables two-factor authentication for accounts-password and accounts-passwordless.
 
There are no required changes to your application in any case, but if you want to provide 2FA for your users, and you are already using accounts-password or accounts-passwordless you can start using the new functions provided from 2FA package.
At its core, a web application offers its users a view into, and a way to modify, a persistent set of data. Whether managing a list of todos, or ordering a car to pick you up, you are interacting with a permanent but constantly changing data layer.
 
In Meteor, that data layer is typically stored in MongoDB. A set of related data in MongoDB is referred to as a “collection”. In Meteor you access MongoDB through collections, making them the primary persistence mechanism for your app data.

Server-side collections : When you create a collection on the server:
Todos = new Mongo.Collection('todos');
You are creating a collection within MongoDB, and an interface to that collection to be used on the server. It’s a fairly straightforward layer on top of the underlying Node MongoDB driver, but with a synchronous API:
// This line won't complete until the insert is done
Todos.insert({_id: 'my-todo'});
// So this line will return something
const todo = Todos.findOne({_id: 'my-todo'});
// Look ma, no callbacks!
console.log(todo);
Client-side collections : On the client, when you write the same line:
Todos = new Mongo.Collection('todos');
It does something totally different!
 
On the client, there is no direct connection to the MongoDB database, and in fact a synchronous API to it is not possible (nor probably what you want). Instead, on the client, a collection is a client side cache of the database. This is achieved thanks to the Minimongo library—an in-memory, all JS, implementation of the MongoDB API.
// This line is changing an in-memory Minimongo data structure
Todos.insert({_id: 'my-todo'});
// And this line is querying it
const todo = Todos.findOne({_id: 'my-todo'});
// So this happens right away!
console.log(todo);
The way that you move data from the server (and MongoDB-backed) collection into the client (in-memory) collection is the subject of the data loading article. Generally speaking, you subscribe to a publication, which pushes data from the server to the client. Usually, you can assume that the client contains an up-to-date copy of some subset of the full MongoDB collection.
 
To write data back to the server, you use a Method, the subject of the methods article.
 
Local collections : There is a third way to use a collection in Meteor. On the client or server, if you create a collection in one of these two ways:
SelectedTodos = new Mongo.Collection(null);
SelectedTodos = new Mongo.Collection('selectedtodos', {connection: null});
This creates a local collection. This is a Minimongo collection that has no database connection (ordinarily a collection would either be directly connected to the database on the server, or via a subscription on the client).
 
A local collection is a convenient way to use the full power of the Minimongo library for in-memory storage.
Now we can attach helpers to documents, we can define a helper that fetches related documents
Lists.helpers({
  todos() {
    return Todos.find({listId: this._id}, {sort: {createdAt: -1}});
  }
});
Now we can find all the todos for a list :
const list = Lists.findOne();
console.log(`The first list has ${list.todos().count()} todos`);
We can use the dburles:collection-helpers package to easily attach such methods (or “helpers”) to documents. For instance:
Lists.helpers({
  // A list is considered to be private if it has a userId set
  isPrivate() {
    return !!this.userId;
  }
});
Once we’ve attached this helper to the Lists collection, every time we fetch a list from the database (on the client or server), it will have a .isPrivate() function available :
const list = Lists.findOne();
if (list.isPrivate()) {
  console.log('The first list is private!');
}
On the client, Session provides a global object that may be used to hold an arbitrary set of key-value pairs. It can be used to save information such as the currently chosen item in a list. When the user exits the app, the data will be removed.
 
Syntax :
Session.set(key, value);
Run the following command in your terminal to add Session to your application :
meteor add session
Creating Meteor Application And Importing Module :
 
Step 1 : Create a React application using the following command.
meteor create foldername
Step 2 : After creating your project folder i.e. foldername, move to it using the following command.
cd foldername
Step 3 : Import Session module from ‘meteor/session’
import { Session } from 'meteor/session'

Step to Run Application : Run the application from the root directory of the project, using the following command.

meteor


Example : This is the basic example that shows how to use the Sessions component.

Main.html :

<head>
    <title>FreeTimeLearn</title>
</head>
 <body>
    <div>
        {{> employee}}
    </div>
</body>
<template name="employee">
    <h1 class="heading">FreeTimeLearn</h1>
    <p>
        Session provides a global object that may
        be used to hold an arbitrary set of key-value pairs.
    </p>
</template>

Main.js :

import { Session } from 'meteor/session';
import './main.html';
var emp = {
    FirstName: "John",
    LastName: "Smith",
    Age: 10,
    Designation: "System Architecture"
}
Session.set('data', emp);
var display = Session.get('data');
console.log(display);

Output : 
Meteor

Source : meteor