Building a news app using RedwoodJS
07.12.2022 - 12:27
In this tutorial, we will learn about the RedwoodJS framework by building a News app. We will learn a lot from this tutorial, we will learn how to use RedwoodJS CLI tool to scaffold components, GraphQL definitions, pages, etc ; How to create a RedwoodJS application and how to fetch data in RedwoodJS. We are going to learn a lot here. So let's begin by understanding what RedwoodJS actually is and how it works.

What is RedwoodJS

RedwoodJS is a full-stack React framework used to build modern web applications. This framework was started by Tom Preston-Werner, the cofounder of GitHub.

RedwoodJS uses so many technologies:

RedwoodJS is so helpful that a basic Redwood application contains both the frontend code, backend, and database readily set up for us. Its CLI code generators generate codes for any component or GraphQL services we create.

With RedwoodJS you are way-half done in your project. We need to have some software and tools installed in your machine before we can use RedwoodJS, let's see them below.

Requirements

  • Node.js: Both Strapi and Reactjs are Node.js-based tools and frameworks respectively. To download Nodejs binary, get it from here.
  • NPM: This is a Node.js package manager. This comes bundled with the Node.js binary. Run the command npm --version to confirm.
  • VS Code: A web editor from Microsoft. You can use other editors but VS Code is quite amazing and has a worldwide adoption by devs. So VS Code is recommended for this tutorial. You can download it from here.

We don't have to install any database because RedwoodJS by default uses SQLite.

So we start with the creation of the News app. The first thing we need to scaffold a RedwoodJS project, let's see that is done below.

Scaffolding a RedwoodJS project

A RedwoodJS project is scaffolded via command-line using either Yarn, NPM, or NPX. Run the below command to create a RedwoodJS project:


yarn create redwood-app newsapp-redwood
# OR
npx create-redwood-app newsapp-redwood

The above commands will create a RedwoodJS in a newsapp-redwood folder.

Using yarn tool, the create sub-command tells yarn that we want to create a project. The redwood-app sub-command tells it that we want to create a Redwoojs project. The newsapp-redwood is the folder we want the RedwoodJS project to be created in.

The npx is similar to yarn, the difference is that the create and redwood-app are conjoined.

Move into the newsapp-redwood folder: cd newsapp-redwood.

To start a Redwood app, we run the command:


yarn rw dev

The rw is Redwood, it tells Yarn that we are trying to run a Redwood command. The Redwood command is dev, this command starts the Redwood server in a Redwood application. Open the URL localhost:8910 in a browser, RedwoodJS does it for you automatically though. You will see the page open:

RedwoodJS initial page
RedwoodJS initial page

Building News model

We are building a news website, a single news item will have this model:


newsItem {
    title
    body
    writtenBy
    imageUrl
}

  • The title is the title of the news.
  • The body is the content of the news.
  • The writtenBy is the author of the news.
  • The imageUrl is the head image of the news.
Bạn đang tìm hiểuHọc tiếng Đức & Du học Đức?
Đội ngũ chuyên gia giàu kinh nghiệm của chúng tôi sẵn lòng tư vấn và đưa ra phương án phù hợp nhất

CÔNG TY TNHH ĐINH NGUYỄN GIA

Công ty TNHH Đinh Nguyễn Gia là đơn vị tư vấn giáo dục uy tín có trụ sở tại TP. HCM. Sở hữu đội ngũ chuyên viên giàu kinh nghiệm cùng mạng lưới đối tác toàn cầu.

Địa chỉ

99 Hoàng Sa, Phường Võ Thị Sáu, Quận 3, TP. Hồ Chí Minh, Việt Nam.
Điện thoại: 090 6060 279
Email: info@dinhnguyengia.edu.vn
Website: dinhnguyengia.edu.vn