Express Transporter

This project is based on a problem in this paper.

Running the Website

Clone it:

git clone https://www.github.com/jetsup/express-transporters.git

Install dependencies:

npm install

Create Database credentials. Copy credentials.template.ts to credentials.ts. If on VS code, CTRL+click here and it will be created, or run on terminal:

cp src/db/credentials.template.ts src/db/credentials.ts # UNIX and Windows Powershell

OR

COPY src\db\credentials.template.ts src\db\credentials.ts # Windows Command Prompt

Modify the credentials as per your requirement.

However, if database name, in credentials.template.ts, is changed, it should also changed in the first three lines of schema.sql.

Data

The routes in routes/index.ts gives the url path you can navigate in the browser to perform CRUD operation on various entities. For conveniency, Data should be inserted through the web browser which ensures that the all foreign key are correctly matched.

All the CRUD operations are properly defined in routes/index.ts and mapped to respective URP paths.

Seeding The Database (Dummy Data)

Alternatively, for the create operation, you can seed the database to contain dummy data, for testing purposes. The seeding script defines all dummy migrations and uses the faker-js library.

Change the variables at the top of seeding script depending on your need.

To seed, run:

npm run seed

Note

In the seed.ts script, error handling is not implemented correctly, running the seed multiple times would result in duplication errors in some tables and foreign key conflict. The if (err) { return; } simply ignores the error and cancels the database commit.



Deleting The Database (Restore Default)

To delete all the data from the database , run:

npm run clean-db

This command will ask for a password if your Database server is password protected then drop the entire database then recreate it using schema.sql script.

This command should be run cautiously.



This project uses MariaDB/MySQL therefore tables can also be manipulated directly using SQL Commands.

Running the server

Nodemon is used so that it can refresh the server every time the TypeScript files changes.

[Dev] Open terminal and run:

nodemon --exec npm run start -e ts

Uses typescript and the starts script has its prestart set to compile the typescript files using tsc.

Testing

To test the CRUD operations, we are using jest, run:

npm test

Additional Info and/or Directives

More.md