Quickstarters

How to Build a CRUD App with Node.js?

33min

Overview

In this walkthrough, you will learn how to develop a complete CRUD (create, read, update, delete) application using Node.js.

We will utilize Back4app as our backend service to simplify data management. This guide will walk you through configuring a Back4app project, designing a dynamic data model, and implementing CRUD operations using Node.js.

Initially, you will set up a Back4app project named Basic-CRUD-App-Node which provides a robust, non-relational data storage solution.

You will then design your data schema by defining collections and fields either manually or by leveraging the Back4app AI Agent.

Next, you will manage your backend through the Back4app Admin App—a user-friendly, drag-and-drop interface for data manipulation.

Finally, you will integrate your Node.js application with Back4app using the Parse JavaScript SDK (or the REST/GraphQL API as needed) while ensuring secure access controls.

By the end of this tutorial, you will have built a production-ready Node.js application capable of performing essential CRUD operations along with user authentication and data security.

What You Will Learn

  • How to create a Node.js-based CRUD application with an effective low-code backend.
  • Strategies for designing a scalable backend and connecting it with your Node.js app.
  • How to utilize the Back4app Admin App for streamlined create, read, update, and delete operations.
  • Deployment techniques, including Docker containerization, to efficiently launch your Node.js application.


Prerequisites

Before diving in, make sure you have:

  • A Back4app account with a freshly configured project. Need help? Visit Getting Started with Back4app.
  • A Node.js development setup. Use a code editor like Visual Studio Code and ensure Node.js (v14 or later) is installed.
  • Basic knowledge of Node.js, asynchronous programming, and REST APIs. Refer to the Node.js documentation if needed.


Step 1 – Setting Up Your Project

Creating a New Back4app Project

  1. Log into your Back4app account.
  2. Click on the “New App” button from your dashboard.
  3. Name your project: Basic-CRUD-App-Node and follow the on-screen prompts to complete the setup.
Create New Project
Create New Project


After creation, your project will appear on your dashboard, ready for backend configuration.



Step 2 – Crafting Your Data Schema

Defining Your Data Structures

For this CRUD application, you will create several collections in your Back4app project. Below are examples of the key collections and fields needed for basic CRUD functionality.

1. Items Collection

This collection stores details about each item.

Field

Type

Description

_id

ObjectId

Auto-generated unique identifier.

title

String

The name of the item.

description

String

A brief overview of the item.

createdAt

Date

Timestamp marking when the item was added.

updatedAt

Date

Timestamp marking the last update.

2. Users Collection

This collection handles user credentials and authentication data.

Field

Type

Description

_id

ObjectId

Auto-generated unique identifier.

username

String

Unique name for the user.

email

String

Unique email address of the user.

passwordHash

String

Hashed password for secure authentication.

createdAt

Date

Timestamp when the account was created.

updatedAt

Date

Timestamp when the account was updated.

You can create these collections and fields manually via the Back4app dashboard.

Create New Class
Create New Class


You can add columns by choosing a data type, naming the field, setting default values, and marking them as required.

Create Column
Create Column


Utilizing the Back4app AI Agent for Schema Generation

The Back4app AI Agent simplifies schema setup by automatically generating your data model based on your description. This speeds up configuration and ensures your data structures support all CRUD operations.

How to Use the AI Agent:

  1. Open the AI Agent: Access the AI Agent from your Back4app project settings.
  2. Outline Your Data Schema: Describe the collections and fields you need.
  3. Review and Apply: The AI Agent will suggest a schema. Review the proposal and apply the changes.

Example Prompt

Text


This method ensures a consistent and optimized data model.



Step 3 – Enabling the Admin App & Performing CRUD Operations

Overview of the Admin App

The Back4app Admin App provides a no-code interface for managing your backend data. Its drag-and-drop design makes it simple to execute CRUD tasks like adding, viewing, updating, and deleting records.

Activating the Admin App

  1. Go to the “More” section in your Back4app dashboard.
  2. Select “Admin App” and click “Enable Admin App.”
  3. Configure your admin credentials by setting up your initial admin account. This process will also create roles (e.g., B4aAdminUser) and system classes.
Enable Admin App
Enable Admin App


After activation, log in to the Admin App to manage your data.

Admin App Dashboard
Admin App Dashboard


Managing CRUD Operations with the Admin App

Inside the Admin App you can:

  • Insert Records: Use the “Add Record” button within a collection (for example, Items) to create new entries.
  • Review and Edit Records: Click on any record to inspect its details or update its fields.
  • Delete Records: Remove entries that are no longer required.

This user-friendly interface simplifies data management considerably.



Step 4 – Linking Your Node.js Application with Back4app

With your backend set up, it’s time to connect your Node.js app to Back4app.

Option A: Using the Parse JavaScript SDK

  1. Install the Parse JavaScript SDK: Run the following command in your project directory:

    Bash
    
  2. Initialize Parse in Your Node.js Application: Create a configuration file (e.g., parseConfig.js):

    JS
    



Text


Option B: Using REST or GraphQL

If you prefer not to use the Parse SDK, you can interact with Back4app via REST API calls. For instance, here is how to retrieve items using Node.js:

JS


Integrate these REST calls into your Node.js services as needed.



Step 5 – Strengthening Your Backend Security

Configuring Access Control Lists (ACLs)

Enhance your data security by setting ACLs on your objects. For example, to make an item accessible only to its creator:

JS


Setting Class-Level Permissions (CLPs)

Adjust CLPs in your Back4app dashboard to enforce default security rules, ensuring that only authenticated users can interact with specific collections.



Step 6 – Implementing User Authentication

Configuring User Management

Back4app leverages Parse’s built-in User collection to manage authentication. In your Node.js app, implement user sign-up and login as shown below:

JS


A similar approach can be used for session management and additional authentication features.



Step 7 – Deploying Your Node.js Application

Back4app provides a smooth deployment process. You can deploy your Node.js app using several methods, including Docker containerization.

7.1 Building Your Application

  1. Compile and Package: Use your preferred build tool (such as npm or yarn) to prepare your application.

    For example, run:

    Bash
    
  2. Verify Your Build: Ensure that your production bundle contains all required modules and files.


7.2 Organizing Your Project Layout

A typical Node.js project structure might look like:

Text


7.3 Dockerizing Your Node.js App

If you prefer containerized deployment, add a Dockerfile to your project root:

Dockerfile


7.4 Deploying via Back4app Web Deployment

  1. Connect Your GitHub Repository: Host your Node.js source code on GitHub.
  2. Configure Deployment Settings: In your Back4app dashboard, choose the Web Deployment option, link your repository (e.g., Basic-CRUD-App-Node), and select the desired branch.
  3. Set Build and Output Commands: Define your build command (e.g., npm run build) and specify the output folder.
  4. Deploy Your App: Click Deploy and monitor the logs until your application is live.


Step 8 – Wrapping Up and Future Enhancements

Congratulations! You have now built a Node.js CRUD application integrated with Back4app.

You configured a project called Basic-CRUD-App-Node, established collections for Items and Users, and managed your backend with the Back4app Admin App.

Furthermore, you connected your Node.js app via the Parse JavaScript SDK (or REST/GraphQL) and implemented strong security measures.

Next Steps:

  • Enhance Your Application: Consider adding features such as advanced filtering, detailed views, or real-time updates.
  • Expand Backend Capabilities: Explore cloud functions, third-party API integrations, or role-based access controls.
  • Deepen Your Expertise: Check out the Back4app documentation and additional tutorials to further refine your application.

Happy coding and best wishes on your journey with your Node.js CRUD application!