---
title: "How To Build A Web Application with TypeScript and Remix | CoderPad"
description: "Remix is a full-stack web framework that focuses on the user interface and works backwards through web standards to provide a quick, slick, and dependable user experience. Learn how to build a full-stack web application with Typescript and the Remix framework in this article."
canonical: "https://coderpad.io/blog/development/how-to-build-a-web-application-with-typescript-and-remix/"
last_modified: "2026-04-15 16:21:03"
---
[Back to blog](https://coderpad.io/blog/)

# How To Build A Web Application with TypeScript and Remix

November 17, 2022 6 Minute Read

By Uma Victor

[Development](https://coderpad.io/blog/development/)

Remix is a full-stack web framework that focuses on the user interface and works backwards through web standards to provide a quick, slick, and dependable user experience. It focuses on web standards and modern web app UX, allowing you to create better websites quickly. In addition, it can run anywhere because it is built on the Web Fetch API.

Remix runs natively on Cloudflare Workers and includes support for both serverless and traditional Node.js environments. In addition, it was designed to address web applications’ page speed issues to provide a better user experience.

In this article, you’ll learn the Remix framework and how to use it by building a full-stack web application using Remix and TypeScript.

## Prerequisites

To get the best out of this tutorial, ensure you have met the following requirements:

- [Node.js](https://nodejs.org/en/) version 14 or later installed
- [PostgreSQL](https://www.postgresql.org/) database installed
- Knowledge of [TypeScript](https://www.typescriptlang.org/)

## Setting up a new Remix project

With the above requirements met, proceed to set up a new Remix project by running the command below in your terminal:

```
$ npx create-remix@latest
```

The command above will prompt you to choose the configurations for the project. First, you’ll call our app`task-app`, choose Just the basics, then the Remix App Server deploy target, use TypeScript, and have it run the installation for you.

Installation prompt from the`npx create-remix@latest`command.

After the installation is complete, the command will create the following folder structures below:

```
📦task-app

┣ 📂app

┃ ┣ 📂routes

┃ ┃ ┗ 📜index.tsx

┃ ┣ 📜entry.client.tsx

┃ ┣ 📜entry.server.tsx

┃ ┗ 📜root.tsx

┣ 📂public

┃ ┗ 📜favicon.ico

┣ 📜.eslintrc.js

┣ 📜.gitignore

┣ 📜README.md

┣ 📜package.json

┣ 📜remix.config.js

┣ 📜remix.env.d.ts

┗ 📜tsconfig.jsonCode language: CSS (css)
```

Now run the application locally on a computer with the command`npm run dev`and navigate to [http://localhost:300](http://localhost:3001/) on your browser.

The Remix framework’s welcome page.

## Connect to a database

Now, let’s connect your application to a database to allow you to save the user’s record. First, we’ll combine the application with a PostgreSQL database using the Prisma ORM. To get started, you’ll need to install the Prisma package in your project by running the commands below.

```
$ npm install Prisma --save-dev
```

Then initialize Prisma using the CLI tool by running the command below:

```
$ npx prisma init --datasource-provider postgresql
```

The above command will create a new Prisma directory in the project root folder with a Prisma schema file and configures PostgreSQL as your database with some dummy credentials. First, you’ll need to update`DATABASE_URL`in the .env file created by the prisma command with your database credentials.

## Create schema

With the database configurations all set up, let’s create a schema to define how the data stored in our database will be organized. To do that, open the`Prisma/schema.prisma`file and replace the code with the code snippets below.

```
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "Prisma-client-js"
}

data source DB {
  provider = "PostgreSQL"
  URL      = env("DATABASE_URL")
}

model Task {
  id        String  @id @default(UUID())
  name      String
  completed Boolean
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}Code language: TypeScript (typescript)
```

In the code snippet above, we define a`Task`schema with the fields we want in our task table in our database. The`id`field will be a randomly generated string achieved using the [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) library. We have the`name`field, which is also a string, a`completed`field to know the task’s status, a boolean, and`createAt`and`UpdateAt`fields to keep track of when the task was created and updated.

Now let’s run a migration to create a database table from the schema you define with the command below.

```
$ npx Prisma migrate dev --name init
```

The above command will create a new SQL migration file in the`prisma/migrations`directory and run the SQL migration file against the database. At this point, your database is set for use.

## Create application components

Components in Remix have been created in the`app`folder in the`routes`directory. Inside the routes folder, you can create the components for your application.

By default, Remix creates an`index.ts`file with an`Index`component. This component is rendered when you visit the root URL of the web application. Since we are only causing the tasks in the application, we’ll update the`routes/index.ts`file with the code snippet below.

```
export default function Index() {
  return (
    <div className="container">
      <div className="task-tab">
        <h4>Task List</h4>
        <hr />
        <div>
          <form action="" method="POST" className="form">
            <input type="text" name="name" />
            <button type="submit">Add</button>
          </form>
        </div>
        <div className="task-list">
          <ul>
              <li>
                <p>Task 1</p>
                <input type="checkbox" name="brand" id="" />
              </li>
          </ul>
        </div>
      </div>
    </div>
  );
}Code language: JavaScript (javascript)
```

## Style the application

To make the application look appealing, you need to add some styling to the application. We’ll create a custom style and export at route layout boundaries (`root.ts`file) in the route function in the links export function. Create a`styles`directory in the`app`folder to get started.

In the styles directory, create a`global.css`file and add the following:

```
* {
  padding: 0px;
  margin: 0px;
  box-sizing: border-box;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.container .task-tab {
  box-shadow: rgba(50, 50, 93, 0.25) 0px 13px 27px -5px,
    rgba(0, 0, 0, 0.3) 0px 8px 16px -8px;
  padding: 20px;
}
.container .task-tab h4 {
  margin-bottom: 5px;
  font-size: 25px;
}

.container .task-tab .form {
  width: 400px;
  display: flex;
  margin-top: 5px;
}

.container .task-tab .form button {
  padding: 10px;
  border: 1px solid rgb(217, 217, 217);
  border-left: 0px;
}
.container .task-tab .form input {
  width: 100%;
  padding: 10px;
  outline: none;
  border: 1px solid RGB(217, 217, 217);
  border-right: 0px;
}
.container .task-list ul li {
  padding: 10px;
  display: flex;
  justify-content: space-between;
  background-color: rgb(230, 235, 235);
  margin-top: 10px;
  margin-bottom: 10px;
}
.container .task-list ul li .done {
  text-decoration: line-through;
}Code language: CSS (css)
```

Then update the root.ts file to import and make the styles available to your components.

```
//...
import styles from "~/styles/global.css";
export function links() {
  return [{ rel: "stylesheet", href: styles }];
}
//...Code language: TypeScript (typescript)
```

Now refresh your browser and you should see the output below.

The Task List application with a cancelled task 1.

At this point, we have a hard-coded task in our application. First, let’s create some routes to create and read data from our database.

## Create API routes

API routes in Remix are created in the`app/routes/api`folder. Every file in the`api`folder is treated as an API route. We’ll create three routes to create a new task, read the tasks and update the status of the task. But first, we need to initialize the Prisma client to allow you to send queries to your database.

Create a`config`folder in the`app`directory to do that. Then inside the config folder, create a`dbConfig.ts`file and add the code:

```
import { PrismaClient } from "@prisma/client";
let prisma: PrismaClient;

declare global {
  const DB: PrismaClient | undefined;
}

if (process.env.NODE_ENV === "production") {
  prisma = new PrismaClient();
  prisma.$connect();
} else {
  if (!global.db) {
    global.db = new PrismaClient();
    global.db.$connect();
  }
  prisma = global.db;
}

export { prisma };Code language: TypeScript (typescript)
```

In the code snippet above, we initialized the`PrismaClient`in a variable`prisma`to create a connection with our application and database, ensuring that a new connection is not created when our application reloads the development environment.

Next, create a`createTask.ts`file in the`api`folder and add the code:

```
import type { ActionFunction } from "@remix-run/node";
import { prisma } from "../../config/dbConfig";

export const action: ActionFunction = async ({ request }) => {
  const data = await request.json();
  const newTask = await prisma.task.create({
    data: { name: data.name, completed: false },
  });
  return newTask;
};Code language: TypeScript (typescript)
```

In the code snippet above, we imported the`ActionFunction`type for TypeScript, which we’ll use to show the type for our`action`function. When you make a POST, PUT, and DELETE requests to Remix API, it will locate the action function and execute the code in the function. Next, we created an action function to add new records to the database using the`prisma`client initiated in the dbConfig file. The prisma client object provides us with the methods required to perform CRUD operations on our database.

Now update the`index.ts`file to send a request to the API to create a new task with the code snippet below.

```
import { useState } from "react";
export default function Index() {
  const [task, setTask] = useState('');

  const createTask = async () =>
    await fetch("http://localhost:3000/api/createTask", {
      method: "POST",
      body: JSON.stringify({
        name: Task
      })
    })
  return (
    <div className="container">
      <div className="task-tab">
        <h4>Task List</h4>
        <hr />
        <div>
          <form className="form" onSubmit={createTask}>
            <input type="text" name="name" onChange={(e) => setTask(e.target.value)} />
            <button type="submit">Add</button>
          </form>
        </div>
        <div className="task-list">
          <ul>
              <li>
                <p>Task 1</p>
                <input type="checkbox" name="brand" id="" />
              </li>
          </ul>
        </div>
      </div>
    </div>
  );
}Code language: JavaScript (javascript)
```

## Read data from the database

Next, create a`getTasks.ts`file in the`api`folder and add the code snippets below to get all the tasks in your database.

```
import type { LoaderFunction } from "@remix-run/node";
import { prisma } from "../../config/dbConfig";

export const loader: LoaderFunction = async () => {
  return prisma.task.findMany();
};Code language: TypeScript (typescript)
```

Here, we imported the`LoaderFunction`type to specify the type for our loader function. Like the action function, Remix executes the code in a loader function whenever you send a GET request to the API. So we used the`prima.findMany`method to get all the tasks in our database.

Finally, update the code in the`index.ts`file to loop through all the tasks from our API and display and render them on our UI:

```
//...
import { json } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";

type Task = {
  id: string;
  name: string;
  completed: boolean;
  createdAt: Date;
  updatedAt: Date;
}

export async function loader() {
  const res = await fetch("http://localhost:3000/api/getTask");
  return json(await res.json());
}

export default function Index() {
  //...
  const tasks = useLoaderData();
  return (
    <div className="container">
      <div className="task-tab">
        <h4>Task List</h4>
        <hr />
        <div>
          <form className="form" onSubmit={createTask}>
            <input type="text" name="name" onChange={(e) => setTask(e.target.value)} />
            <button type="submit">Add</button>
          </form>
        </div>
        <div className="task-list">
          <ul>
            {tasks.map((task: Task) => (
              <li key={task.id}>
                <p className={task.completed ? 'done' : ""}>{task.name}</p>
                <input type="checkbox" name="brand" id="" />
              </li>
            ))}
          </ul>
        </div>
      </div>
    </div>
  );
}Code language: JavaScript (javascript)
```

In the code snippet above, we imported the JSON function to parse the response return from the API,`useLoaderData`hook to load the data from the returned in the`loader`function to your components. Then we created a task to define the structure of data from the API, and then we looped through the task data and rendered them on the component.

Now, go ahead and add some tasks to the application, and you should see a similar output to the one on the screenshot below, depending on the tasks you’ve created.

The Task List final application.

## Conclusion

In this tutorial, you learned to build a web application with TypeScript and Remix. You learned how to set up a Remix app, connect the Remix application to a database using Prisma, create an application schema with prisma, and perform create and read operations.The code used in this article can be found in this [GitHub repository](https://github.com/uma-victor1/remix-task-app).

Remix is an exciting tool, and I recommend checking out the Remix [documentation](https://remix.run/docs/en/v1) to learn more. Finally, I hope you enjoyed this article, and happy coding!

Uma Victor is a software developer based in Nigeria who is familiar with a variety of different web technologies and frameworks. He is also keen on finding ways to explain things as simple as possible. You can reach out to me on [twitter](https://twitter.com/umavictor_).

## Subscribe for more CoderPad insights

## Trending Articles

Previous slide Next slide [Development

## What is Prompt Engineering?

Introducing AI tools such as ChatGPT and Bard helps increase the efficiency of tasks such as data generation, code generation and completion, text summarization, etc. How were these AI tools trained to answer almost every question you ask them? The answer, prompt engineering, is discussed in this blog post.

Read the post](https://coderpad.io/blog/development/what-is-prompt-engineering/) [Development

## A Guide To Using React’s useCallback() Hook

Are you looking to optimize your React applications? Have you heard of the useCallback hook? useCallback is a powerful React hook that helps you optimize your application by preventing unnecessary re-renders. In this post, we'll dive into React's useCallback() hook, define referential equality and callback functions and how to tie it all together.

Read the post](https://coderpad.io/blog/development/a-guide-to-using-reacts-usecallback-hook/) [Development

## MySQL vs. PostgreSQL: How Do They Compare?

A database is a convenient tool that allows users to access information, maintain records, and apply commonly used operations, such as insertion, modification, deletion, and data organization. Learn about MySQL vs PostgreSQL, their features, advantages, and disadvantages. Finally, check out which one is the best choice for you.

Read the post](https://coderpad.io/blog/development/mysql-vs-postgresql-how-do-they-compare/) [Development

## PostgreSQL LIKE Operator: A Detailed Guide

When using databases, searching for values that match a given pattern is a familiar necessity. Learn how you can retrieve entries with queries including a particular string using Postgres LIKE operator.

Read the post](https://coderpad.io/blog/development/postgresql-like-operator-a-detailed-guide/) [Development

## How To Use DataProvider In TestNG With Examples

When it comes to testing there are many tools and techniques available. In this post, we'll discuss how to use DataProvider with TestNG.

Read the post](https://coderpad.io/blog/development/how-to-use-dataprovider-in-testng-with-examples/) [Development

## How To Get Up And Running With Django Migrations: A Guide

Django migrations are a way of handling the application of changes to a database schema. By following the steps outlined in this guide, you can easily set up and use migrations in your Django projects.

Read the post](https://coderpad.io/blog/development/how-to-get-up-and-running-with-django-migrations-a-guide/) [Development

## Writing A Parameterized Test In JUnit With Examples

A JUnit parameterized test allows you to decouple data from structure, generating cleaner and more reliable tests. Learn more in this guide.

Read the post](https://coderpad.io/blog/development/writing-a-parameterized-test-in-junit-with-examples/) [Development

## How To Use Assert In JUnit With Examples

The JUnit Assert class is what you use to write unit testing assertions in JUnit. Learn more about it in this guide, full of examples.

Read the post](https://coderpad.io/blog/development/how-to-use-assert-in-junit-with-examples/) [Development

## A Simple Guide To TypeORM: What It Is And How To Use It

Considering current languages have object-oriented programming features, most database management systems are based on the relational model, with tables instead of objects. For these reasons, mapping relational objects is very important in development. In this article, you will learn what TypeORM, one of the main tools used today, is.

Read the post](https://coderpad.io/blog/development/a-simple-guide-to-typeorm-what-it-is-and-how-to-use-it/) [Development

## Using PreparedStatement in JDBC With Examples

In this post, we'll see why and how to work with JDBC and PreparedStatement. We will also learn along with examples using code.

Read the post](https://coderpad.io/blog/development/using-preparedstatement-in-jdbc-with-examples/) [Development

## React vs React Native: The Differences Explained

React and React Native are similar in that they both allow web developers to build applications based on the unique concept of components. But the two frameworks do this in radically different ways. In this post, we cover the key differences between react and react native frameworks, implementation, and which is an appropriate choice.

Read the post](https://coderpad.io/blog/development/react-vs-react-native-the-differences-explained/) [Development

## Logging in Django

The most challenging part of fixing a problem is identifying it. Unfortunately, this statement is exceptionally true when it comes to debugging. Learn how to use the power of logging into your Django applications to improve your debug process in this article.

Read the post](https://coderpad.io/blog/development/logging-in-django/)

## Hire with confidence.

See why engineering teams trust CoderPad to evaluate developers with realistic, AI-ready hiring workflows.

[Request a demo](https://coderpad.io/sales/)
