Quickstarters
CRUD Samples
How to Develop a CRUD App with TypeScript?
34 min
overview in this walkthrough, you'll learn how to construct a crud (create, read, update, delete) application using typescript we'll utilize back4app as the backend platform, making data management straightforward this guide covers setting up a back4app project, modeling your data, and integrating crud functionality into a typescript application initially, you'll create a project on back4app called basic crud app typescript which offers a flexible nosql storage solution you'll design your data structure by defining classes and fields either manually or with the assistance of back4app's ai agent next, you'll use the back4app admin app for backend management via a user friendly interface that simplifies data operations finally, you'll connect your typescript application with back4app using the parse javascript sdk, ensuring secure access and authentication by the end of this tutorial, you'll have a fully operational typescript application capable of handling basic crud tasks, including user authentication and data management what you'll learn how to build a typescript based crud application with a nosql backend methods for designing a scalable backend integrated with a typescript front end how to leverage back4app’s admin app to manage your data effortlessly strategies for deployment, including docker containerization, to launch your typescript app smoothly 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 typescript development environment use an editor like visual studio code and ensure you have node js installed basic knowledge of typescript, object oriented programming, and restful apis if needed, refer to the typescript documentation https //www typescriptlang org/docs/ step 1 – project initialization setting up a new back4app project log in to your back4app account click on the “new app” button in your dashboard enter the project name basic crud app typescript and follow the steps to complete project creation create new project after the project is established, it will appear on your dashboard, serving as the foundation for your backend step 2 – crafting the data schema defining your data structures for this application, you will create a couple of collections (classes) on back4app below are examples of essential classes with fields that facilitate crud operations 1\ items collection field data type description id objectid auto generated unique identifier title string name or title of the item description string a brief description of the item createdat date timestamp when the item was created updatedat date timestamp for the latest update 2\ users collection field data type description id objectid auto generated unique identifier username string unique name for the user email string unique email address passwordhash string securely hashed password for login createdat date account creation timestamp updatedat date timestamp for the last account update you can create these collections and fields manually in the back4app dashboard create new class when adding fields, choose the data type, name the field, set a default value if necessary, and indicate if it’s mandatory create column using the back4app ai agent for schema configuration the integrated ai agent in back4app can automatically generate your data schema from a description this simplifies setup and ensures your model is ready for crud operations how to use the ai agent open the ai agent log into your back4app dashboard and locate the ai agent in your project settings describe your schema provide a detailed description of the collections and fields you require review and confirm the ai agent will propose a schema review it and confirm to apply the changes example prompt 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 method saves time and guarantees a well structured schema step 3 – using the admin app for crud operations overview of the admin app the back4app admin app provides a no code interface that makes managing your backend data simple its drag and drop features allow you to perform crud operations—such as adding, reading, updating, and deleting records—without hassle enabling the admin app go to the “more” menu on your back4app dashboard choose “admin app” and click on “enable admin app ” set up your admin credentials by creating an initial admin account, which will also define roles like b4aadminuser and system classes enable admin app after activation, sign in to the admin app to manage your data admin app dashboard managing crud operations with the admin app within the admin app you can insert records use the “add record” function in any collection (e g , items) to input new data review and edit click on a record to view details or modify fields delete records remove entries that are no longer needed this intuitive interface enhances data management by simplifying routine tasks step 4 – connecting your typescript app to back4app with your backend ready, the next step is to link your typescript application with back4app option a employing the parse javascript sdk install the parse javascript sdk using npm, run npm install parse initialize parse in your typescript application create a configuration file (e g , parseconfig ts ) // parseconfig ts import parse from 'parse'; export function initializeparse() { parse initialize('your application id', 'your javascript key'); parse serverurl = 'https //parseapi back4app com'; } 3\ implement crud functions in typescript for example, create a service for managing items ```typescript // itemsservice ts import parse from 'parse'; export async function fetchitems() promise\<parse object\[]> { const query = new parse query('items'); try { return await query find(); } catch (error) { console error('error fetching items ', error); return \[]; } } export async function additem(title string, description string) promise\<void> { const item = new parse object('items'); item set('title', title); item set('description', description); try { await item save(); console log('item added successfully '); } catch (error) { console error('error adding item ', error); } } export async function updateitem(objectid string, newtitle string, newdescription string) promise\<void> { 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 async function removeitem(objectid string) promise\<void> { const query = new parse query('items'); try { const item = await query get(objectid); await item destroy(); console log('item removed successfully '); } catch (error) { console error('error removing item ', error); } } option b utilizing rest or graphql if you prefer not to use the parse sdk, you can perform crud operations via rest for example, to retrieve items using rest import fetch from 'node fetch'; export async function getitemsviarest() { 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('data retrieved ', data); } catch (error) { console error('error retrieving items ', error); } } integrate these api calls as needed within your typescript modules step 5 – ensuring backend security setting up access control lists (acls) secure your data by applying acls to your objects for example, to create an item that only its owner can access import parse from 'parse'; export async function createsecureitem(title string, description string, owner parse user) { const item = new parse object('items'); item set('title', title); item set('description', description); const acl = new parse acl(); acl setreadaccess(owner, true); acl setwriteaccess(owner, true); acl setpublicreadaccess(false); acl setpublicwriteaccess(false); item setacl(acl); try { await item save(); console log('secure item created successfully '); } catch (error) { console error('error creating secure item ', error); } } managing class level permissions (clps) adjust clps via the back4app dashboard to enforce access restrictions so that only authenticated users can interact with certain collections step 6 – implementing user authentication managing user accounts back4app leverages parse's built in user class to handle authentication in your typescript application, implement user registration and login as follows import parse from 'parse'; export async function registeruser(username string, password string, email string) promise\<void> { 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('registration error ', error); } } export async function loginuser(username string, password string) promise\<void> { try { const user = await parse user login(username, password); console log('user logged in ', user get('username')); } catch (error) { console error('login failed ', error); } } this approach can be extended for session management, password resets, and other authentication features step 7 – deploying your typescript application back4app simplifies the deployment process you can deploy your typescript application using methods like docker containerization 7 1 building your typescript app compile and bundle use your build tool (such as webpack or tsc) to compile and bundle your application for example, to compile with tsc tsc confirm the output ensure the generated files include all necessary assets and modules 7 2 organizing your project structure a typical typescript project might look like this basic crud app typescript/ \| src/ \| | index ts \| | parseconfig ts \| | services/ \| | itemsservice ts \| | authservice ts \| package json \| tsconfig json \| readme md example parseconfig ts // parseconfig ts import parse from 'parse'; export function initializeparse() { parse initialize('your application id', 'your javascript key'); parse serverurl = 'https //parseapi back4app com'; } 7 3 dockerizing your typescript application if you choose containerization, add a dockerfile to your project root \# use an official node js runtime as a parent image from node 18 alpine \# set the working directory workdir /usr/src/app \# copy package files and install dependencies copy package json / run npm install \# bundle app source code copy \# build the typescript app run npm run build \# expose port (adjust as needed) expose 3000 \# start the app cmd \[ "node", "dist/index js" ] 7 4 deploying via back4app web deployment link your github repository ensure your typescript project is hosted on github set up deployment settings in the back4app dashboard, use the web deployment option to connect your repository (e g , basic crud app typescript ) and select the appropriate branch define build and output commands specify the build command (like npm run build ) and indicate the output directory deploy your application click deploy and follow the logs until your application is live step 8 – final thoughts and future enhancements congratulations! you have successfully created a typescript based crud application integrated with back4app you set up a project named basic crud app typescript , designed collections for items and users, and managed your data using the back4app admin app additionally, you connected your typescript app via the parse javascript sdk (or rest/graphql) and implemented robust security measures what’s next? expand your application integrate additional features such as advanced filtering, detailed item views, or real time data updates enhance backend capabilities explore cloud functions, integrate third party apis, or implement role based permissions further learning visit the back4app documentation https //www back4app com/docs and check out additional guides to optimize your application happy coding and enjoy building your typescript crud application!