Quickstarters
CRUD Samples
Building a CRUD App with Inferno.js: A Comprehensive Walkthrough
41 min
overview this guide will show you how to construct a full featured crud (create, read, update, delete) application using inferno js you'll learn how to handle fundamental data operations by developing a crud system that efficiently manipulates and updates information our backend foundation is powered by back4app, where you'll establish a project named basic crud app infernojs to manage your data seamlessly you'll first set up your back4app project and design a scalable database schema by defining classes and fields—either manually or with the back4app ai assistant this process ensures your data structures are robust enough for all crud tasks following that, you'll utilize the back4app admin interface, a no code drag and drop tool that makes data management straightforward finally, you'll link your inferno js frontend with back4app using either the sdk (if it fits your setup) or via api calls, all while employing stringent access controls for security by the end of this tutorial, you'll have a production level web application featuring user authentication, dynamic data handling, and a responsive interface core insights master crud functionalities with a robust backend on back4app understand how to architect a scalable database schema and integrate it with your inferno js frontend explore a visual management tool for effortlessly executing create, read, update, and delete operations learn deployment strategies, including containerization with docker requirements a back4app account and a newly created project if you need guidance, check out getting started with back4app https //www back4app com/docs/get started/new parse app an inferno js development setup use your favorite inferno starter or boilerplate confirm node js (version 14 or newer) is installed a basic understanding of javascript, inferno js, and rest api principles for extra details, consult the inferno documentation https //infernojs org/docs/introduction before diving in, please ensure you have step 1 – initializing your project launching a new back4app project sign in to your back4app account select the “new app” option from your dashboard name your project basic crud app infernojs and follow the on screen steps to complete creation create new project after creation, your project appears in your dashboard, providing a solid backend platform for your app step 2 – crafting the database schema defining your data model for this crud application, you'll establish several classes below are examples of two essential classes with their fields, set up to support crud operations 1\ the items class field type details id objectid auto generated primary key title string the item’s title description string a short explanation of the item created at date timestamp marking when the item was created updated at date timestamp for the most recent update 2\ the users class field type details id objectid auto generated primary key username string unique identifier for the user email string user's unique email address password hash string encrypted password for secure authentication created at date timestamp for account creation updated at date timestamp for the last account update manually create these classes on the back4app dashboard by selecting “new class” and adding the necessary columns create new class you can define each field by selecting a data type, providing a name, and setting defaults or requirements create column leveraging the back4app ai assistant for schema setup the back4app ai assistant simplifies schema creation by auto generating classes based on your descriptions how to use the ai assistant access the ai assistant sign in to your back4app dashboard and locate the ai assistant in the settings detail your data model input a comprehensive description of the classes and fields you require review and implement the assistant will propose class definitions confirm and apply these settings example prompt create the following classes in my back4app app 1\) class items \ fields \ id objectid (auto generated) \ title string \ description string \ created at date (auto set) \ updated at date (auto update) 2\) class users \ fields \ id objectid (auto generated) \ username string (unique) \ email string (unique) \ password hash string \ created at date (auto set) \ updated at date (auto update) using the ai assistant streamlines your setup, ensuring consistency and efficiency step 3 – activating the admin interface & crud functions introducing the admin interface the back4app admin interface is a powerful, no code tool that offers a drag and drop experience for managing your backend it allows you to effortlessly execute crud operations activating the admin interface go to the “more” section in your back4app dashboard click “admin app” and then hit “enable admin app ” set up your admin account by creating your initial admin user this process automatically configures roles and essential system classes enable admin app after enabling, sign in to the admin interface to manage your data admin app dashboard performing crud via the admin interface inside the admin interface, you can create entries use the “add record” option within a class (like items) to insert new data read/modify entries click on any record to view or update its details remove entries utilize the delete feature to clear out unwanted records this interface greatly enhances usability by simplifying all crud tasks step 4 – connecting inferno js with back4app with your backend configured via the admin interface, it’s time to integrate your inferno js frontend option a utilizing the parse sdk install the parse sdk npm install parse initialize parse in your inferno app create a configuration file (e g , src/parseconfig js ) // src/parseconfig js import parse from 'parse'; // insert your back4app credentials here parse initialize('your application id', 'your javascript key'); parse serverurl = 'https //parseapi back4app com'; export default parse; implement parse in an inferno component for instance, build a component to retrieve and list items // src/components/itemslist js import { component } from 'inferno'; import parse from ' /parseconfig'; class itemslist extends component { constructor(props) { super(props); this state = { items \[] }; } componentdidmount() { this loaditems(); } async loaditems() { const items = parse object extend("items"); const query = new parse query(items); try { const results = await query find(); this setstate({ items results }); } catch (err) { console error("error loading items ", err); } } render() { return ( \<div> \<h2>items\</h2> \<ul> {this state items map(item => ( \<li key={item id}> {item get("title")} — {item get("description")} \</li> ))} \</ul> \</div> ); } } export default itemslist; option b using rest or graphql apis if the parse sdk isn’t ideal for your scenario, you can execute crud actions via rest or graphql for example, to retrieve items with rest // rest api call to retrieve items const fetchitems = async () => { try { const response = await fetch('https //parseapi back4app com/classes/items', { 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 retrieved ', data results); } catch (err) { console error('error fetching items ', err); } }; fetchitems(); embed these api calls within your inferno components as necessary step 5 – fortifying your backend implementing access control lists (acls) ensure data security by assigning acls for instance, to generate a private item async function createprivateitem(itemdata, owner) { const items = parse object extend('items'); const item = new items(); item set('title', itemdata title); item set('description', itemdata description); // set acl so only the owner has access const acl = new parse acl(owner); acl setpublicreadaccess(false); acl setpublicwriteaccess(false); item setacl(acl); try { const saveditem = await item save(); console log('private item created ', saveditem); } catch (err) { console error('error creating item ', err); } } configuring class level permissions (clps) within your back4app dashboard, adjust clps for each class to enforce default access policies, ensuring only authorized users can interact with sensitive data step 6 – managing user authentication establishing user accounts back4app utilizes the user class (via parse) for handling authentication in your inferno js app, implement registration and login functions as illustrated below // src/components/auth js import { component } from 'inferno'; import parse from ' /parseconfig'; export class signup extends component { constructor(props) { super(props); this state = { username '', password '', email '' }; } handlesignup = async (e) => { e preventdefault(); const user = new parse user(); user set('username', this state username); user set('password', this state password); user set('email', this state email); try { await user signup(); alert('registration successful!'); } catch (err) { alert('sign up error ' + err message); } }; render() { return ( \<form onsubmit={this handlesignup}> \<input type="text" placeholder="username" value={this state username} oninput={e => this setstate({ username e target value })} /> \<input type="password" placeholder="password" value={this state password} oninput={e => this setstate({ password e target value })} /> \<input type="email" placeholder="email" value={this state email} oninput={e => this setstate({ email e target value })} /> \<button type="submit">sign up\</button> \</form> ); } } a similar strategy applies for login and session management additional features like social authentication, email verification, and password recovery can be set up in the back4app dashboard step 7 – deploying your inferno js frontend back4app’s web deployment option lets you host your inferno js frontend effortlessly by linking your github repository 7 1 building for production open your project directory in a terminal run the production build command npm run build this command compiles your application into a build folder containing optimized static assets confirm the build verify that the build folder includes an index html file and other asset folders 7 2 organizing and uploading your code your repository should include the complete source of your inferno js frontend an example directory structure basic crud app infernojs frontend/ \| node modules/ \| public/ \| ` index html \| src/ \| | app js \| | parseconfig js \| ` components/ \| | itemslist js \| ` auth js \| package json ` readme md sample files src/parseconfig js // src/parseconfig js import parse from 'parse'; // insert your back4app credentials here parse initialize('your application id', 'your javascript key'); parse serverurl = 'https //parseapi back4app com'; export default parse; src/app js // src/app js import { component } from 'inferno'; import parse from ' /parseconfig'; class app extends component { constructor(props) { super(props); this state = { items \[], newtitle "", newdescription "", editid null, edittitle "", editdescription "" }; } componentdidmount() { this loaditems(); } async loaditems() { const items = parse object extend("items"); const query = new parse query(items); try { const results = await query find(); this setstate({ items results }); } catch (err) { console error("error loading items ", err); } } handleadd = async () => { const items = parse object extend("items"); const item = new items(); item set("title", this state newtitle); item set("description", this state newdescription); try { await item save(); this setstate({ newtitle "", newdescription "" }); this loaditems(); } catch (err) { console error("error adding item ", err); } } handledelete = async (id) => { try { const item = await parse object createwithoutdata("items", id); await item destroy(); this loaditems(); } catch (err) { console error("error deleting item ", err); } } startedit = (item) => { this setstate({ editid item id, edittitle item get("title"), editdescription item get("description") }); } handleupdate = async () => { try { const items = parse object extend("items"); const item = new items(); item id = this state editid; item set("title", this state edittitle); item set("description", this state editdescription); await item save(); this setstate({ editid null, edittitle "", editdescription "" }); this loaditems(); } catch (err) { console error("error updating item ", err); } } render() { return ( \<div style={{ padding '2rem' }}> \<h1>items\</h1> \<div style={{ marginbottom '1rem' }}> \<h2>add new item\</h2> \<input type="text" placeholder="title" value={this state newtitle} oninput={e => this setstate({ newtitle e target value })} style={{ marginright '0 5rem' }} /> \<input type="text" placeholder="description" value={this state newdescription} oninput={e => this setstate({ newdescription e target value })} style={{ marginright '0 5rem' }} /> \<button onclick={this handleadd}>add item\</button> \</div> \<h2>items list\</h2> \<ul> {this state items map(item => ( \<li key={item id} style={{ marginbottom '1rem' }}> {this state editid === item id ? ( \<div> \<input type="text" value={this state edittitle} oninput={e => this setstate({ edittitle e target value })} style={{ marginright '0 5rem' }} /> \<input type="text" value={this state editdescription} oninput={e => this setstate({ editdescription e target value })} style={{ marginright '0 5rem' }} /> \<button onclick={this handleupdate}>save\</button> \<button onclick={() => this setstate({ editid null })} style={{ marginleft '0 5rem' }}> cancel \</button> \</div> ) ( \<div> \<strong>{item get("title")}\</strong> {item get("description")} \<button onclick={() => this startedit(item)} style={{ marginleft '1rem' }}> edit \</button> \<button onclick={() => this handledelete(item id)} style={{ marginleft '0 5rem' }}> delete \</button> \</div> )} \</li> ))} \</ul> \</div> ); } } export default app; pushing your code to github initialize git in your project folder git init stage your files git add commit your changes git commit m "initial commit for inferno js frontend" create a github repository name it basic crud app infernojs frontend push your project git remote add origin https //github com/your username/basic crud app infernojs frontend git git push u origin main 7 3 connecting github with back4app web deployment go to web deployment log in to back4app, select your project ( basic crud app infernojs ), and click on the web deployment feature integrate with github follow the prompts to link your github account, enabling back4app to access your repository choose your repository and branch pick the repository (e g , basic crud app infernojs frontend ) and the branch (typically main ) that contains your code 7 4 deployment settings enter additional configurations build command if your repo lacks a pre built build folder, specify a command like npm run build back4app will execute this during deployment output folder set the output to build so back4app knows where your static files reside environment variables add any necessary variables (such as api keys) within the configuration settings 7 5 dockerizing your application if you opt for containerization, include a dockerfile in your repository similar to \# use an official node image for the build stage 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 remaining files and build the app copy run npm run build \# use nginx to serve the built app from nginx\ stable alpine copy from=build /app/build /usr/share/nginx/html expose 80 cmd \["nginx", " g", "daemon off;"] select docker deployment in back4app if you choose this method 7 6 launching your application click deploy once all settings are configured, hit the deploy button watch the build back4app will fetch your code, build your project, and deploy it in a container access your app after deployment, back4app provides a url where your inferno js app is live 7 7 confirming the deployment visit the provided url open the url in your browser test functionality ensure the app loads, all routes operate correctly, and assets (css, js, images) display as expected troubleshoot use developer tools to inspect for errors if issues appear, check back4app logs and verify github settings step 8 – wrapping up and future directions congratulations! you’ve created a full crud application with inferno js and back4app you set up the project basic crud app infernojs , designed your data classes, and used the intuitive admin interface for data management your frontend is now connected and secured with robust access controls next steps enhance the ui expand your inferno js app with detailed views, search capabilities, and live notifications add more features consider implementing additional backend functions (such as cloud code), integrating third party apis, or introducing role based access explore further dive into the back4app documentation https //www back4app com/docs and additional tutorials for performance tuning and custom integrations happy coding and best of luck with your future projects!