Monday, November 18, 2024
Google search engine

Meteor Core API

Meteor is a full-stack JavaScript platform that is used for developing modern web and mobile applications. Meteor has a set of features that are helpful in creating a responsive and reactive web or mobile application using JavaScript or different packages available in the framework. It is used to build connected-client reactive applications.

You can use Meteor.isClient to limit the code to only run on the client-side and Meteor.isServer to limit the code to only run on the server-side. Anything outside of .isClient and .isServer is gonna run on both.

Syntax:

if (Meteor.isClient) {
   // The code is now running on the client...
}

if (Meteor.isServer) {
   // The code is now running on the server....
}

 

Creating Meteor Application and Importing Module:

Step 1: Create a Meteor 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 Meteor module from ‘meteor/meteor’

import { Meteor } from 'meteor/meteor'

Project Structure: It will look like the following.

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

meteor

Example: It is the basic example that shows how to use the Core API component.

Main.html




<head>
    <title>gfg</title>
</head>
  
<body>
    <h1 class="heading">neveropen</h1>
  
    {{> hello}}
    <!-- {{> info}} -->
</body>
  
<template name="hello">
    <p>
      You can use Meteor.isClient to limit 
      the code to only run on the client-side 
      and Meteor.isServer to limit the code to 
      only run on the server-side. 
    </p>
</template>


Main.js




import { Template } from 'meteor/templating';
import './main.html';
  
Template.hello.onCreated(function helloOnCreated() {
    if (Meteor.isClient) {
        // The code is now running on the client...
        console.log("Meteor is running in the client?, ",
            Meteor.isClient);
        console.log("Meteor is running in the server?, ",
            Meteor.isServer);
    }
  
    if (Meteor.isServer) {
        // The code is now running on the server....
        console.log("Meteor is running in the client?, ",
            Meteor.isClient);
        console.log("Meteor is running in the server?, ",
            Meteor.isServer);
    }
});


Output:

Reference: https://docs.meteor.com/api/core.html

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments