The server side

Let's create the Posts collection, which will be shared between the server and the client. In the shared folder, create an index.js file. We have only one collection and we can define it in the index.js file:

import {Mongo} from 'meteor/mongo';export const Posts = new Mongo.Collection('posts');

All our data will be passed from the client with Meteor Methods. The first method we can define is create_new_user(). We will call this Method when the user signs up for the first time. In Meteor.startup(() => {}, let's define the methods:

 Meteor.methods({create_new_user(data) {      let profile_number = Math.floor(Math.random() * (10000));Posts.insert({user_id: this.userId,posts: [],                    username: data.username, location: random_coordinates(), ...

Get Build Applications with Meteor now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.