Open In App

Meteor Core API

Last Updated : 07 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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">GeeksforGeeks</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:


Next Article

Similar Reads