How to create an App using Meteor ?
Below is a step-by-step implementation.
Step 1: Installation
- Linux and OS: The cURL command is used to interact with the server by specifying its location and here we are receiving our code to install meteor from the resource provided by the meteor and the sh command is installing that.
curl https://install.meteor.com/ | sh
- Windows: In windows, we will need the node package manager to install meteor.
npm install -g meteor
Step 2: Creating a project with the meteor is so simple, just write the meteor create command in your terminal along with some configurations.
meteor create app-name --option
app-name – This will be our application name.
For example, here we are creating a react based application with `meteor create hello-world –react`
Project Structure: On successful initialization, this would be our folder structure.
Step 3: Run Application. Write the command below to run your meteor app, after the run meteor keeps all changes of files in sync.
Something like this will be shown on your terminal.
Output: When we open http://localhost:3000 to view our application in the browser, something like the screenshot given below will appear. This is the default frontend view of a meteor application.
With this our meteor project is ready and we can start writing our database models, server logic, and the frontend design inside it.
Example 1: In this example, we are going to replace the default frontend content of the meteor. Inside the imports/ui directory there exists an App.jsx file and we can write our react code inside that.
Example 2: This is the sample of how to fetch data from the database and render it on the frontend with the help of Meteor. First of all, we have to create the mongo collection, here we have created a collection named gfglinks and exported it so that it can be used in other files.
Explanation: After the collection being created we can insert data into it. At the backend, we are inserting some data into the collection. Meteor.startup executes some given functionality when the server starts. Notice we are importing LinksCollection which we have exported from the links.js file. The insert method inserts the give data into the database.
Explanation: When data is in our database, we can fetch it to the frontend. Here we are rendering all data that is inserted into the database in the last step. The useTracker is a hook in meteor which takes care of all reactivity of components. LinkCollection is that one which we have exported from the link.js file, the find method finds all data inside it.
Later we are simply rendering some li tags with the help of the map function.
Output: After all this process our application is ready to run, with meteor run something like the GIF given below will be shown up.
Please Login to comment...