Quickstarters
CRUD Samples
How to Build CRUD App with JavaScript?
34 min
overview in this tutorial, you'll learn how to construct a complete crud (create, read, update, delete) application using javascript we will utilize back4app to manage your backend data effortlessly this guide covers essential crud operations, from configuring a back4app project to integrating your javascript application with the parse javascript sdk or rest api initially, you will set up a project on back4app titled basic crud app javascript , which offers a robust backend solution you'll then define your data schema—either manually or with the help of back4app's ai agent—to fit your application’s requirements next, you'll manage your backend through the user friendly back4app admin app, enabling you to perform data operations via a simple drag and drop interface finally, you'll connect your javascript application to back4app, implementing secure user authentication and basic crud functionalities by the end of this guide, you will have built a production ready javascript application capable of performing all fundamental crud operations with secure access control key points to remember master how to develop a javascript based crud app with a scalable backend understand how to structure your backend and integrate it smoothly with your javascript code learn to utilize back4app’s admin app for easy data manipulation and crud operations explore deployment options, including containerization with docker, to launch your javascript application prerequisites before you begin, make sure you have a back4app account with a configured project need help? visit getting started with back4app https //www back4app com/docs/get started/new parse app a javascript development setup you can use visual studio code or any other preferred editor along with node js (version 14 or later) basic knowledge of javascript, modern frameworks, and rest apis refer to the javascript documentation https //developer mozilla org/en us/docs/web/javascript if needed step 1 – initializing your project setting up a new back4app project log into your back4app account click on the “new app” button from your dashboard enter the project name basic crud app javascript and complete the setup process create new project once the project is created, it appears on your dashboard, laying the groundwork for your backend configuration step 2 – crafting your data schema designing data structures for our crud app, we will establish two primary classes (collections) on back4app these classes and their fields are essential for handling the necessary crud operations 1\ the items collection this collection stores details for each item field type details id objectid auto generated unique identifier title string the item’s name description string a brief summary of the item createdat date timestamp of item creation updatedat date timestamp of the latest update 2\ the users collection this collection handles user credentials and authentication details field type details id objectid automatically generated unique id username string unique identifier for the user email string the user's unique email address passwordhash string hashed password for secure authentication createdat date account creation timestamp updatedat date last account update timestamp you can create these classes and their fields directly in the back4app dashboard create new class you can add columns by selecting a type, naming the field, assigning default values, and setting mandatory options create column using back4app's ai agent for schema generation the back4app ai agent simplifies schema creation by auto generating your data model based on your description this feature accelerates project setup and ensures your schema aligns with your crud requirements how to utilize the ai agent open the ai agent log into your back4app dashboard and find the ai agent in the project settings describe your schema input a detailed description of the collections and fields needed review and confirm after processing, the ai agent will display a proposed schema review and confirm to apply it sample description create the following collections in my back4app project 1\) collection items \ fields \ id objectid (auto generated) \ title string \ description string \ createdat date (auto generated) \ updatedat date (auto updated) 2\) collection users \ fields \ id objectid (auto generated) \ username string (unique) \ email string (unique) \ passwordhash string \ createdat date (auto generated) \ updatedat date (auto updated) this ai assisted approach saves time and guarantees a well structured data model for your app step 3 – enabling the admin app & performing crud operations overview of the admin app the back4app admin app offers a code free interface for efficient backend data management with its intuitive drag and drop features, you can effortlessly perform crud operations like adding, viewing, modifying, and deleting records activating the admin app go to the “more” section in your back4app dashboard select “admin app” and click on “enable admin app ” configure your admin credentials by setting up the initial admin account this also establishes roles like b4aadminuser and system classes enable admin app after activation, log into the admin app to manage your application’s data admin app dashboard managing crud operations via the admin app inside the admin app, you can insert records use the “add record” option to create new entries in a collection like items view and edit records click on any record to see details or modify fields delete records remove any records that are no longer needed this simple interface streamlines data management and enhances overall usability step 4 – connecting your javascript app with back4app with the backend set, the next step is to integrate your javascript application with back4app option a utilizing the parse javascript sdk include the parse sdk if you are using npm, install the sdk by running npm install parse initialize parse in your application create an initialization file (e g , parseconfig js ) // parseconfig js import parse from 'parse'; parse initialize("your application id", "your javascript key"); parse serverurl = 'https //parseapi back4app com'; 3\ implement crud functions for example, create a module to handle item operations ```javascript // itemsservice js import parse from 'parse'; export const getitems = async () => { const query = new parse query("items"); try { const results = await query find(); return results; } catch (error) { console error("error retrieving items ", error); return \[]; } }; export const createitem = async (title, description) => { const item = parse object extend("items"); const item = new item(); item set("title", title); item set("description", description); try { await item save(); console log("item created successfully "); } catch (error) { console error("error creating item ", error); } }; export const updateitem = async (objectid, newtitle, newdescription) => { const query = new parse query("items"); try { const item = await query get(objectid); item set("title", newtitle); item set("description", newdescription); await item save(); console log("item updated successfully "); } catch (error) { console error("error updating item ", error); } }; export const deleteitem = async (objectid) => { const query = new parse query("items"); try { const item = await query get(objectid); await item destroy(); console log("item deleted successfully "); } catch (error) { console error("error deleting item ", error); } }; option b using rest or graphql if you prefer not to use the parse sdk, you can interact with back4app through rest calls for instance, to retrieve items using rest import fetch from 'node fetch'; export const fetchitemsrest = async () => { try { const response = await fetch('https //parseapi back4app com/classes/items', { method 'get', headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key', }, }); const data = await response json(); console log("items fetched ", data); } catch (error) { console error("error fetching items via rest ", error); } }; integrate these api calls within your javascript modules as needed step 5 – protecting your backend configuring access controls ensure your data is secure by setting up access control lists (acls) for instance, to create an item accessible only by its creator import parse from 'parse'; export const createprivateitem = async (title, description, user) => { const item = parse object extend("items"); const item = new item(); item set("title", title); item set("description", description); const acl = new parse acl(); acl setreadaccess(user, true); acl setwriteaccess(user, true); acl setpublicreadaccess(false); acl setpublicwriteaccess(false); item setacl(acl); try { await item save(); console log("private item created successfully "); } catch (error) { console error("error creating private item ", error); } }; adjusting class level permissions (clps) set default access rules for your collections via the back4app dashboard, ensuring that only authenticated users can access sensitive data step 6 – implementing user authentication setting up user accounts back4app uses the built in parse user class to handle authentication in your javascript application, manage user registration and login as follows import parse from 'parse'; export const signupuser = async (username, password, email) => { const user = new parse user(); user set("username", username); user set("password", password); user set("email", email); try { await user signup(); console log("user registered successfully!"); } catch (error) { console error("error during sign up ", error); } }; export const loginuser = async (username, password) => { try { const user = await parse user login(username, password); console log("logged in as ", user get("username")); } catch (error) { console error("login failed ", error); } }; this method can be extended for session management, password recovery, and more step 7 – deploying your javascript application back4app simplifies deployment you can deploy your javascript app using methods like docker containerization 7 1 building your application bundle your application use your build tool (like webpack or a similar bundler) to compile your code verify the build ensure that your bundled files contain all the necessary modules and assets 7 2 organizing your project structure a typical javascript project structure might look like basic crud app javascript/ \| src/ \| | index js \| | parseconfig js \| | services/ \| | itemsservice js \| | authservice js \| public/ \| | index html \| package json \| readme md example parseconfig js // parseconfig js import parse from 'parse'; parse initialize("your application id", "your javascript key"); parse serverurl = 'https //parseapi back4app com'; 7 3 dockerizing your javascript app if you choose containerization, include a dockerfile in your project root \# use an official node js runtime as the base image from node 14 alpine \# set the working directory in the container workdir /app \# copy package files and install dependencies copy package json / run npm install \# copy the rest of the application code copy \# expose the application port (adjust if necessary) expose 3000 \# define the command to run your application cmd \["npm", "start"] 7 4 deploying via back4app web deployment connect your github repository make sure your javascript project is hosted on github configure deployment settings in the back4app dashboard, use the web deployment option to link your repository (e g , basic crud app javascript ) and select the desired branch set build and output commands specify your build command (such as npm run build ) and the output directory deploy hit deploy and watch the logs until your application goes live step 8 – final thoughts and future enhancements congratulations! you have successfully developed a javascript based crud application integrated with back4app you set up a project called basic crud app javascript , structured your items and users collections, and managed your backend using the back4app admin app additionally, you connected your javascript application via the parse sdk (or rest api) and implemented robust security measures what to explore next enhance functionality consider adding features like search filters, detailed views, or real time data updates expand backend features look into cloud functions, integrating third party apis, or implementing advanced role based access controls deepen your expertise visit the back4app documentation https //www back4app com/docs and explore additional tutorials to further optimize your app happy coding, and enjoy building your advanced javascript crud application!