Name: EJ Mason
Gitub: https://github.com/EJMason
email: [email protected]
linkedin: linkedin.com/in/eliotmason/
- Navigate to the project root:
cd headspace-book-node-api
-
Install the required packages in the package.json
-
Note: A lot of the typescript features use newer versions of Node. It is preferred to have Version > 8.0. It can be downloaded here:
yarn install
yarn build
yarn start
- this will install the packages, build the typscript into ./dist and start the server
npm run install:npm
note: the packages can be installed individually:
npm run install
npm run build
npm run start
or...
/<path to project>/node_modules/.bin/tsc
/<path to project>/node_modules/.bin/node ./dist/server.js
* other scripts listed in package.json
- Typescript
- Express
- Jest unit tests
- gulp
- supertest mock api testing
Since I developed this application for a coding challenge I put a lot of the code in the same floders that I normally separate. I wanted to make it easier to read so grouped the code a little more. For instance, for each route I use a router, controller, utility and services folder. This time I only created 2 files.
- PostgresQL relational database
- Build out my own ORM using Node Postgres library
- see ./sql for all the raw query files
I designed the schema in this way so the users_books relation table (many-to-many) would keep track of the collections or librairies of each user. I also created an authors table to reduce how much space the authors would consume.
All queries are performed with raw sql. The files are in the repository. The actual sql files are consumed which enables the sql to be changed without bringing down the database.
There are a lot of things I would have done differently for the overall design of the application.
-
Authentication would be a must. Using JWT would have made the routes much more simple since users could pass user information in the Bearer header.
-
Caching the queries would be useful here. It might take a while for data to become stale with a library application.
-
Better Typing for Typescript. As the project wore on I was forced to use the any keyword to finish, but I would love to interface all the data in the application. I LOVE Typscript + Node + Express.
API conform to REST principles and ensure the enpoints made sense for CRUD operations. Explanations for each endpoint below:
-
CREATE new user :
POST /users
-
GET users books :
GET /users/books
- filter by author
?author={name}
- filter by read
?read={true/false}
- filers may be combined
- filter by author
-
CREATE new book :
POST /books
-
Add book to user Library :
PUT /user/:users_id/books/books_id
-
Delete from Library :
DELETE /users/:users_id/books/:books_id
-
Set book status true for user :
PUT /books/read
-
Set book status false for user :
PUT /books/unread
The database is a could instance so you should be able to connect.Once the server is running, the easiest way to test the API will be using the postman sample file I have created. download it here:
-
Database connects to an external instance. See .env file for urls.
-
Unfortunalty, half of the unit tests are no longer working since a sql library I started with didn't suport typescript. My tests where running with the typescript code and I didn't know until I had written all the tests. Sadly, not enough time to refactor them.
-
Feel free to contact me with any questions in regards to the application!