Hosting App on Heroku

Whilst trying to get my app live onto Heroku, I realized that there were a lot of kinks that I needed to get right. This post attempts to document the complete series of steps on getting both the frontend built statically and copied into the backend, as well as getting the backend hosted on heroku. Steps on hosting both frontend and backend of your app on Heroku Step 1: Ensure cors is installed in backend npm install cors ...

June 28, 2023 · 3 min · Lei

Understanding Docusign ESignature API

So in this app that I am building, I need to integrate an e-signature feature where the user clicks a button, and the PDF file is being sent directly via Docusign to the client to request for signature. Of course, I don’t have any idea whether this is possible. Luckily, I discovered that Docusign actually has an API service. In this post, I am going to document everything that I learn about it. ...

May 22, 2023 · 10 min · Lei

Uploading Binary Files Into MongoDB

So part of my requirements for Kotakit was that I needed to upload PDFs into MongoDB. And I’ve never done that before. After googling, it turns out that for files less than 16mb, I could simply upload them as binary files. I also know next to nothing about the binary format. After an afternoon of tinkering around, I’ve finally managed to upload a binary file into my local instance of Mongodb. So here’s an attempt to note down everything that I’ve learned about the process and what is required. ...

May 19, 2023 · 6 min · Lei

Uploading Files to Express

I’ve never uploaded a blob file to an express backend, or MongoDB before. All the times that I’ve learned backend development, I was mainly handling JSON data types. Which is why, when I tried sending a POST request to an express backend with a body that contains a File data type, this error occurred: 1 2 request entity too large PayloadTooLargeError: request entity too large After a quick googling, it turns out that there are a few things that I’ll need to know about “uploading” files to a DB through an express backend. ...

May 16, 2023 · 2 min · Lei

Notes on Error handling

The hallmark of an experienced developer is his/her ability to foresee the errors and handle them appropriately. Below are some notes regarding how error handling is done in different contexts. Let’s first take a look at the general structure of error handling. Structure of error handling Within a .then().catch() block For instance, within a route, you want to find the noteById, and then do something. 1 2 3 4 5 6 Note.findById(id) .then(note => note) .catch(error => { console.log(error) response.status(500).end() }) Often times, when you’re making a request to the database, it’s unclear whether your request will succeed. If there is an error, you’ll need a .catch() block to handle the error. The catch block receives a callback function with error as argument - an error handler function - and you’ll then define how to handle this error. ...

September 24, 2021 · 5 min · Lei

Steps for Implementing a More Robust Backend Development Architecture Part2

In part 1, we mainly looked at laying out the groundwork for the backend project, including setting up console logging (morgan), eslint, installing various dependencies, configuration for MongoDB connection, util files such as logger, creating the models I needed, coding the express app (app.js), and finally, populating the database with some initial data to work with. In this part, I’ll begin by documenting how I go about creating and testing the routes. Then, we’ll look at middleware and error handling. Finally, I’ll connect the frontend to the backend to make sure that all the data is being pulled correctly. ...

September 23, 2021 · 4 min · Lei

Steps for Implementing a More Robust Backend Development Architecture (Part 1)

You’ve arrived at the moment where your project is getting serious and you need to begin coding some serious backend. This guide will get you started. Goal of Backend Restructure Goal of the development project is to get the backend to look like this: Backend architecture: Index.js App.js Routers: Streams Router Trades Router User Router Login Router Models Trades Model Streams Model User Model Utils Middleware Logger config.js Tests setting up test environment Laying the groundworks Step 1: Take stock of current project dependencies and structure Examine package.json to see what dependencies it currently have. Examine the project folder structure and files to check where is the backend mostly stored. For a simple express server, it is possible that all the routes, middleware, models, are stored in index.js. ...

September 22, 2021 · 8 min · Lei

Refactoring Express Backend

I feel like there is a lot to take in for this part. Whilst in the last part, all of the backend logic was basically stored in index.js, now we’ve refactored each portion into their own separate modules. Indeed, I can see how this could be an overkill for smaller apps, but for more complex projects, it would certainly ‘make developing the app much easier’. Let’s take a look at how that is done, line by line. ...

September 10, 2021 · 6 min · Lei

Steps for Setting Up the Backend During Development

Alrighttttt I am about to embark on some backend development for my Streams app. This document acts as a kind of guide for future development processes, as the exact processes are rather rusty in my mind. I am starting out from completely no backend on my simple React app, with a couple of frontend components. I think the first thing I need to do is to set up an express server. ...

August 25, 2021 · 3 min · Lei