Skip to content

TODO is a simple web application that introduces you to the power, performance, and simplicity of MariaDB. The TODO app contains a React.js front-end and Node.js back-end, which utilizes the MariaDB Node.js connector

License

Notifications You must be signed in to change notification settings

mariadb-developers/todo-app-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TODO

TODO is a web application that introduces you to the power, performance, and simplicity of MariaDB.

This README will walk you through the steps for getting the TODO web application up and running using MariaDB.

Table of Contents

  1. Requirements
  2. Getting started with MariaDB
  3. Get the code
  4. Create the database and table
  5. Configure, build and run the app
    1. Configure
    2. Build and run
  6. Support and contribution
  7. License

Requirements

This sample application requires the following to be installed/enabled on your machine:

1.) Getting Started with MariaDB

MariaDB is a community-developed, commercially supported relational database management system, and the database you'll be using for this application.

If you don't have a MariaDB database up and running you can find more information on how to download, install and start using a MariaDB database in the MariaDB Quickstart Guide.

2.) Get the code

Download this repo directly or use git (through CLI or a client) to retrieve the code using git clone:

$ git clone https://github.com/mariadb-developers/todo_app_nodejs.git 

3.) Create the database and table

Connect to your MariaDB database (from Step #2) and execute the following SQL scripts using the following options:

a.) Use the MariaDB command-line client to execute the SQL contained within schema.sql.

Example command:

$ mariadb --host HOST_ADDRESS --port PORT_NO --user USER --password PASSWORD < schema.sql

OR

b.) Copy, paste and execute the raw SQL commands contained in schema.sql using a client of your choice.

CREATE DATABASE todo; CREATE TABLE todo.tasks ( id INT(11) unsigned NOT NULL AUTO_INCREMENT, description VARCHAR(500) NOT NULL, completed BOOLEAN NOT NULL DEFAULT 0, PRIMARY KEY (id) );

4.) Configure, Build and Run the App

This application is made of two parts:

  • Client
    • communicates with the API.
    • is a React.js project located in the client folder.
  • API
    • uses the MariaDB Node.js Connector to connect to MariaDB.
    • is a Node.js project located int the api folder.

a.) Configure the app

Configure the MariaDB connection by adding an .env file to the Node.js project. Add the .env file here (the api folder).

Example implementation:

DB_HOST=<host_address> DB_PORT=<port_number> DB_USER=<username> DB_PASS=<password> DB_NAME=todo 

Configuring db.js

The environmental variables from .env are used within the db.js for the MariaDB Node.js Connector configuration pool settings:

var mariadb = require('mariadb'); require('dotenv').config(); const pool = mariadb.createPool({ host: process.env.DB_HOST, user: process.env.DB_USER, password: process.env.DB_PASS, port: process.env.DB_PORT, database: process.env.DB_NAME, multipleStatements: true, connectionLimit: 5 });

Configuring db.js for the MariaDB cloud database service SkySQL

MariaDB SkySQL requires SSL additions to connection. It's as easy as 1-2-3 (steps below).

var mariadb = require('mariadb'); require('dotenv').config(); // 1.) Access the Node File System package const fs = require("fs"); // 2.) Retrieve the Certificate Authority chain file (wherever you placed it - notice it's just in the Node project root here) const serverCert = [fs.readFileSync("skysql_chain.pem", "utf8")]; var pools = [ mariadb.createPool({ host: process.env.DB_HOST, user: process.env.DB_USER, password: process.env.DB_PASS, port: process.env.DB_PORT, database: process.env.DB_NAME, connectionLimit: 5, // 3.) Add an "ssl" property to the connection pool configuration, using the serverCert const defined above ssl: { ca: serverCert } }) ];

b.) Build and run the app

Within separate terminal windows perform the following steps:

  1. Install the Node.js packages (dependendies) for the client and api apps using the npm install command.

For example:

$ npm install ./src/client $ npm install ./src/api
  1. Run the client and api apps using the npm start command.

For example:

$ npm start --prefix ./src/api $ npm start --prefix ./src/client

Note: You will need to use seperate terminals for the client and api apps.

Support and Contribution

Please feel free to submit PR's, issues or requests to this project project directly.

If you have any other questions, comments, or looking for more information on MariaDB please check out:

Or reach out to us diretly via:

License

License

About

TODO is a simple web application that introduces you to the power, performance, and simplicity of MariaDB. The TODO app contains a React.js front-end and Node.js back-end, which utilizes the MariaDB Node.js connector

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published