Quickstarters
CRUD Samples
How to Build a Basic CRUD App with Meteor? A Step-by-Step Guide
41 min
overview in this guide, you will learn to develop a crud (create, read, update, and delete) application using meteor we will integrate your meteor app with back4app as the backend service, ensuring that your data management is robust and scalable throughout the tutorial, you'll set up a project named basic crud app meteor , define your database schema, and configure your collections—all while utilizing back4app’s powerful features you'll also see how to employ back4app’s admin app for efficient data management and how to secure your backend with advanced access control measures by the end, you'll have a production ready meteor application that supports crud operations along with user authentication main takeaways develop crud functionalities that efficiently handle data operations using back4app design and implement a scalable backend paired with a meteor frontend utilize back4app’s drag and drop admin app to simplify data operations learn deployment strategies, including docker containerization, for your meteor application prerequisites before starting, ensure you have a back4app account with a new project for setup instructions, check out getting started with back4app https //www back4app com/docs/get started/new parse app a meteor development environment install meteor from meteor’s official website https //www meteor com/install and ensure node js (v14 or later) is available basic knowledge of javascript, meteor, and rest apis consult the meteor documentation https //docs meteor com/ for more insights if needed step 1 – project initialization setting up your back4app project sign in to your back4app account click the “new app” option on your dashboard input the project name basic crud app meteor and follow the prompts to create your project create new project after creation, your project will be listed on your back4app dashboard, laying a solid groundwork for your backend setup step 2 – designing the database schema crafting your data model for a basic crud application, you'll need multiple collections below are examples detailing the collections and fields required to manage data operations effectively 1\ collection items this collection holds details for every item field type details id objectid auto generated unique identifier title string name or title of the item description string brief summary of the item created at date timestamp marking item creation updated at date timestamp for the most recent update 2\ collection users this collection manages user information and authentication details field type details id objectid auto generated unique identifier username string unique identifier for the user email string unique email address password hash string securely hashed password created at date timestamp of account creation updated at date timestamp of the latest account update manually add these collections in the back4app dashboard by creating a new class for each and defining the respective fields create new class create each field by selecting its type, specifying a name, adding default values if necessary, and indicating if it’s required create column leveraging the back4app ai agent for schema creation the back4app ai agent streamlines schema generation directly from your dashboard by providing a descriptive prompt outlining your desired collections and fields, the ai agent can automatically create your database schema how to use the ai agent access the ai agent navigate to the ai agent section in your back4app dashboard describe your schema input a detailed prompt specifying the collections and fields you require review and apply evaluate the suggested schema and apply the changes to your project sample prompt create the following collections in my back4app project 1\) collection items \ fields \ id objectid (auto generated) \ title string \ description string \ created at date (auto generated) \ updated at date (auto updated) 2\) collection users \ fields \ id objectid (auto generated) \ username string (unique) \ email string (unique) \ password hash string \ created at date (auto generated) \ updated at date (auto updated) this method ensures your schema is both consistent and optimized for the application’s needs step 3 – activating the admin app & performing crud operations overview of the admin interface back4app’s admin app is an intuitive, no code tool that empowers you to manage backend data effortlessly through drag and drop operations it simplifies creating, reading, updating, and deleting records enabling the admin app go to the “more” menu on your back4app dashboard select “admin app” and click on “enable admin app ” set up admin credentials create an initial admin user, which also configures default roles such as b4aadminuser along with system collections enable admin app after activation, log in to the admin app to begin managing your data admin app dashboard utilizing the admin app for crud tasks within the admin app, you can add records click “add record” in any collection (like items) to create new entries view/modify records select a record to inspect or change its details remove records delete records that are no longer required this interface greatly enhances the user experience by making data operations straightforward step 4 – integrating meteor with back4app now that your backend is configured and managed via the admin app, it’s time to connect your meteor application to back4app using rest apis in meteor you can integrate with back4app by making rest api calls example fetching data via rest below is an example code snippet to fetch items from back4app in a meteor method // /imports/api/items js import { meteor } from 'meteor/meteor'; import { http } from 'meteor/http'; meteor methods({ 'items fetch'() { try { const response = http get('https //parseapi back4app com/classes/items', { headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key' } }); return response data results; } catch (error) { throw new meteor error('fetch failed', 'unable to fetch items '); } } }); integrate similar rest calls within your meteor components or methods for creating, updating, and deleting records step 5 – securing your backend implementing access control lists (acls) protect your data by assigning acls to your objects for instance, to create an item visible only to its owner async function createsecureitem(itemdata, owneruser) { const itempayload = { title itemdata title, description itemdata description, acl { \[owneruser id] { read true, write true }, ' ' { read false, write false } } }; try { const response = await fetch('https //parseapi back4app com/classes/items', { method 'post', headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key', 'content type' 'application/json' }, body json stringify(itempayload) }); const data = await response json(); return data; } catch (error) { console error('error creating secure item ', error); } } configuring class level permissions (clps) within your back4app dashboard, set up clps for each collection to control default access rules this step ensures that only authorized users can access sensitive data step 6 – managing user authentication setting up meteor user accounts back4app leverages parse’s user class for authentication, but in meteor you can handle user registration and login using standard rest calls example user registration via rest // /imports/api/auth js import { http } from 'meteor/http'; export const signupuser = async (username, password, email) => { try { const response = await http post('https //parseapi back4app com/users', { headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key', 'content type' 'application/json' }, data { username, password, email } }); return response data; } catch (error) { throw new meteor error('signup failed', error message); } }; implement similar methods for user login and session management additional features such as email verification and password resets can be managed via the back4app dashboard step 7 – deploying your meteor frontend back4app’s web deployment feature facilitates hosting your meteor application by linking to a github repository follow these steps to deploy your meteor app 7 1 generate your production build open a terminal in your project directory build your meteor app meteor build /output directory this command creates a build directory containing optimized static assets confirm the build ensure that the build output includes an index html and required asset directories 7 2 organize and upload your code your github repository should have the complete source code of your meteor application a typical structure might be basic crud app meteor/ ├── meteor/ ├── client/ │ └── main html ├── server/ │ └── main js ├── imports/ │ ├── api/ │ │ ├── items js │ │ └── auth js │ └── startup/ │ └── index js ├── package json └── readme md sample file /imports/api/items js // /imports/api/items js import { meteor } from 'meteor/meteor'; import { http } from 'meteor/http'; meteor methods({ 'items fetch'() { try { const response = http get('https //parseapi back4app com/classes/items', { headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key' } }); return response data results; } catch (error) { throw new meteor error('fetch failed', 'unable to retrieve items '); } } }); commit your code to github initialize git in your project folder (if not done) git init add all source files git add commit your changes git commit m "initial meteor crud app commit" create a github repository (e g , basic crud app meteor ) push your code git remote add origin https //github com/your username/basic crud app meteor git git push u origin main 7 3 connecting github with back4app web deployment access web deployment sign in to back4app, navigate to your basic crud app meteor project, and click on the web deployment option link your github account follow on screen instructions to integrate your github account select the repository and branch choose your repository (e g , basic crud app meteor ) and the branch containing your code (e g , main ) 7 4 deployment configuration configure the following settings build command if your repository lacks a pre built folder, specify the build command (e g , meteor build /output directory ) output directory indicate the directory (such as the output folder) that holds your static assets environment variables add any required api keys or configurations 7 5 dockerizing your meteor app (optional) if docker is your deployment preference, include a dockerfile like below \# use the official node image as a base from node 16 alpine as build \# set the working directory workdir /app \# copy package files and install dependencies copy package json / run npm install \# copy the app source code copy \# build the meteor app run meteor build /output directory \# serve with nginx from nginx\ stable alpine copy from=build /app/output/bundle/programs/web browser /usr/share/nginx/html expose 80 cmd \["nginx", " g", "daemon off;"] select the docker deployment option in back4app if you opt for containerization 7 6 finalizing your deployment deploy the application click the deploy button after all configurations are complete monitor the build back4app will fetch your code, run the build command, and deploy your app access your url once deployed, back4app will provide a url where your meteor app is live 7 7 verifying the deployment visit the url open the provided url in your browser test functionality check that all routes, styles, and scripts are functioning correctly debug as needed use browser developer tools and back4app logs to resolve any issues step 8 – final thoughts and future enhancements congratulations! you have successfully built a complete crud application using meteor and integrated it with back4app you set up a project named basic crud app meteor , designed a robust database schema for items and users, and managed data via the admin app additionally, you integrated your meteor frontend with back4app using rest apis and applied security measures for data protection next steps extend your frontend add features like detailed views, search functionality, and real time updates implement advanced backend logic consider using meteor methods for more complex operations or integrating additional third party apis consult further resources explore the back4app documentation https //www back4app com/docs and meteor guides https //docs meteor com/ for deeper insights into performance and customization happy coding and enjoy building with meteor and back4app!