Quickstarters
Feature Overview
How to Build a Backend for Deno?
34 min
introduction in this tutorial, you will learn how to build a backend for deno using back4app we will walk through every step to integrate back4app’s key features—database, rest apis, user authentication, file storage, and live queries—into a deno environment you will see how to communicate with back4app through rest endpoints and create a complete infrastructure without managing servers on your own when you use back4app, you can skip configuring servers with deno manually, saving time and effort you will focus on writing simpler code, thanks to deno’s standard library and modern approach by the end of this how to build a backend for deno guide, you will have a clear path to integrate advanced security, cloud code, and scheduled tasks into your deno application once you complete this tutorial, you will be able to run the server, handle rest apis, integrate user authentication, store files, and schedule tasks easily you will also understand how to manage your data with deno’s fetch approach using the back4app rest api prerequisites a back4app account and a new back4app project getting started with back4app https //www back4app com/docs/get started/new parse app if you do not have an account, you can create one for free use the link above to get your project ready install deno you can get deno at https //deno land https //deno land install deno on your operating system and confirm it with deno version familiarity with basic deno concepts such as modules, file systems, deno run allow net , or how to import application modules from the standard library basic knowledge of rest apis we will use fetch calls and headers content type for data handling, so ensure you know the fundamentals of rest and json make sure you have these prerequisites before beginning having your back4app project configured and your local deno environment running will let you follow this tutorial smoothly step 1 – creating a new project on back4app and connecting create a new project the foundation for your deno backend is a back4app project if you have not created one yet log in to your back4app account click the “new app” button in your back4app dashboard give your app a name (e g , “deno backend tutorial”) once your project is ready, it will appear in your back4app dashboard this project is where you will set up databases, security, and apis connect to back4app via rest since we do not have a parse sdk for deno, we will use back4app’s rest api endpoints you can find the application id , rest api key , and server url in your app’s app settings or security & keys section throughout this tutorial, we will use fetch to send requests from deno to back4app be sure to include your api key and headers content type in each call step 2 – setting up the database in this step, you will create a data model on back4app and interact with it using rest apis from deno creating a data model go to the “database” section in your back4app dashboard click “create a new class” and name it, for example, “todo ” add relevant columns (e g , title (string), iscompleted (boolean)) you can also allow parse to create these columns automatically when data is saved creating a data model with the ai agent back4app’s ai agent can design your schema for you open the ai agent in your back4app dashboard describe your data model (e g , “create a todo class with a title, description, and iscompleted field ”) allow the agent to generate the schema automatically this helps you manage more complex schemas quickly reading and writing data using rest api from deno, you can run the server by calling rest endpoints with fetch for example, to create a todo // file called createtodo ts export async function createtodoitem(title string, iscompleted boolean) { const url = "https //parseapi back4app com/classes/todo"; const body = json stringify({ title, iscompleted }); const response = await fetch(url, { method "post", headers { "x parse application id" "your application id", "x parse rest api key" "your rest api key", "content type" "application/json", }, body, }); if (!response ok) { throw new error(`error saving todo ${response statustext}`); } const result = await response json(); return result; } to fetch todos // file called fetchtodos ts export async function fetchtodos() { const url = "https //parseapi back4app com/classes/todo"; const response = await fetch(url, { method "get", headers { "x parse application id" "your application id", "x parse rest api key" "your rest api key", }, }); if (!response ok) { throw new error(`error fetching todos ${response statustext}`); } const result = await response json(); return result; } you can run these with deno run allow net createtodo ts reading and writing data using graphql api back4app also provides a graphql endpoint https //parseapi back4app com/graphql // file called createtodographql ts export async function createtodographql(title string) { const mutation = ` mutation { createtodo(input { fields { title "${title}" iscompleted false } }) { todo { objectid title iscompleted } } } `; const response = await fetch("https //parseapi back4app com/graphql", { 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({ query mutation }), }); const result = await response json(); return result; } working with live queries (optional) live queries update you in real time, but deno does not have a native parse livequery library you can still set up the live query feature in your back4app dashboard for other clients or use a websocket in deno to subscribe manually for more details, see the official live query docs https //www back4app com/docs/platform/live queries step 3 – applying security with acls and clps overview back4app’s acls (access control lists) and clps (class level permissions) protect your data use clps to set default rules for an entire class then use acls for object level restrictions setting up class level permissions open the database section in your back4app dashboard select a class (for example, “todo”) go to the class level permissions tab enable or disable read/write access for the public or for authenticated users as needed configuring acls when creating or updating an object via rest, you can include an acl attribute in the request body for instance const body = json stringify({ title "private task", acl { " " { "read" false, "write" false }, "role\ admins" { "read" true, "write" true }, } }); this example only allows the “admins” role to read or write public access is off step 4 – writing cloud code functions why cloud code cloud code is where you store secure server side logic you do not manage servers yourself you can add validations or triggers for specific classes example cloud code function you can define a cloud function (in javascript) and deploy it to your app for instance, a function to check text length might be parse cloud define("calculatetextlength", async (request) => { const { text } = request params; if (!text) { throw "text parameter is required"; } return { length text length }; }); deployment you can deploy code through the back4app cli https //www back4app com/docs/local development/parse cli or the cloud code panel in your back4app dashboard npm on cloud code you may import external libraries with require() once deployed, the server environment will run them this is helpful for advanced tasks, but do remember that running them from deno is separate from your cloud code environment on back4app step 5 – configuring authentication enable authentication back4app uses the parse user class for authentication while you are working with deno, you can call rest endpoints to manage users sign up and log in using rest async function signupuser(username string, password string, email string) { const url = "https //parseapi back4app com/users"; const body = json stringify({ username, password, email }); const response = await fetch(url, { method "post", headers { "x parse application id" "your application id", "x parse rest api key" "your rest api key", "content type" "application/json", }, body, }); return await response json(); } async function loginuser(username string, password string) { const url = `https //parseapi back4app com/login?username=${username}\&password=${password}`; const response = await fetch(url, { method "get", headers { "x parse application id" "your application id", "x parse rest api key" "your rest api key", }, }); return await response json(); } social login you can set up google, facebook, apple, and other providers on back4app then, you will call the dedicated endpoints with oauth tokens see back4app’s social login docs https //www back4app com/docs/platform/sign in with apple for details step 6 – handling file storage upload and retrieve files to upload files from deno, use a post request to https //parseapi back4app com/files/\<filename> for example async function uploadfile(filedata uint8array, filename string) { const url = `https //parseapi back4app com/files/${filename}`; const response = await fetch(url, { method "post", headers { "x parse application id" "your application id", "x parse rest api key" "your rest api key", "content type" "image/png", }, body filedata, }); return await response json(); } you can then store the resulting file url in your class objects this method is perfect for storing images or documents while you run the server in deno step 7 – email verification and password reset overview verifying emails ensures legitimate access password reset helps users regain access securely dashboard configuration enable email verification in your back4app dashboard under email settings customize your verification templates enable password reset and set your preferred email layout when a user signs up, they receive a verification link if you turned on email verification for password reset, call the rest endpoint post /requestpasswordreset step 8 – scheduling tasks with cloud jobs cloud jobs overview cloud jobs run periodically without human intervention for instance, you can delete old records daily or send routine email reminders parse cloud job("cleanupoldtodos", async (request) => { const todo = parse object extend("todo"); const query = new parse query(todo); const now = new date(); const thirty days = 30 24 60 60 1000; const cutoff = new date(now\ valueof() thirty days); query lessthan("createdat", cutoff); const oldtodos = await query find({ usemasterkey true }); await parse object destroyall(oldtodos, { usemasterkey true }); return `deleted ${oldtodos length} old todos `; }); after deploying this job, you can schedule it in app settings > server settings > background jobs on your back4app dashboard step 9 – integrating webhooks definition a webhook is an http callback triggered when events happen, such as object creation or updates you can integrate with slack, stripe, or any external service configuration open “more” > “webhooks” in the back4app dashboard click “add webhook” and provide the endpoint of your third party service set which triggers or classes you want to send requests this allows external systems to receive data whenever you create or modify objects in back4app step 10 – exploring the back4app admin panel admin panel introduction non technical teams can use this panel to manage data visually it simplifies crud operations and data reviews how to enable go to app dashboard > more > admin app and choose “enable admin app ” create an admin user to log in set a subdomain for your admin app you can then log in to the admin app to manage records securely conclusion in this tutorial, you discovered how to build a backend for deno on back4app you created data models, handled user authentication, learned about acls and clps for security, and scheduled cloud jobs you also saw how to integrate external apis via webhooks and how to run the server or rest apis with deno run allow net commands this setup gets you started fast without manually configuring file systems or standard library complexities for server architecture next steps expand your deno application with additional endpoints and advanced logic using cloud code integrate more services (e g , payment gateways, analytics) with your back4app data reference back4app’s official documentation for deeper security, performance, and logs analysis tips experiment with advanced real time features or deno kv storage, bridging data between your deno runtime and back4app’s robust environment with your new knowledge, you can confidently deploy a secure, scalable, and feature packed deno backend supported by back4app