All Posts

Catch Errors in Nested Awaits
Adam C. |
TryCatch is very useful in JavaScript code to handle errors/exceptions. Without that, our code will die in the middle when there is an exception. Adding TryCatch at the top level of Await/Async may meet our need to prevent the code from interrupting in the middle, but in order for debugging the cause of the error, we would need to add the TryCatch to the nested Await/Async functions.
How to Get IANA Timezone Name from Local Datetime
Adam C. |
Surprisingly there is not a function to get a top-level US timezone. We can get a valid timezone from Intl object, but it is not a top-level, i.e., US/New-York vs US/Easten. Get a top group of US timezone is usually, for it will simplify the timezone selection dropdown. In this article, I will show how to create custom functions using raw IANA data to achieve this goal.
Semantic UI Dropdown with Remote Data
Adam C. |
In this article, I show you how I implemented the tags function using remote data. The frontend is done by the Semantic UI Dropdown component and the backend is implemented using FeathersJS with Mongodb.
CKEditor5 Classic Build DNA Updated
Adam C. |
It has been a while since I last updated my first ever NPM package: ckeditor5-build-classic-dna. Since the office CKEditor5 has been updated to version 30.0.0, I think it's good to keep ckeditor5-build-classic-dna up to date.
Create Upload API with FeathersJS
Adam C. |
"File" is a special type of data submitting to the server. It's encoded as multipart/form-data (i.e., binary data.) It does not like simple key/value pairs from text fields, which could be captured in params or data context of FeathersJS, we would need middleware to covert this to either params or data, and then be saved to the server.
Install MongoDB PHP8 Library On Ubuntu 20.08
Adam C. |
PHP's naming convention is horribly inconsistent! In this article, we learn how to install MongoDB PHP8 Library On Ubuntu 20.08.
FeathersJS Deployment
Adam C. |
In this article, we will learn how to deploy FeathersJS to the Node server along with the Apache server using Reverse Proxy. The PM2 is also used to easily start/stop the application.
Move the existing code to Github Repository
Adam C. |
The right way to move your existing code to Github Repository, so it shows the correct user name. Also, you should make sure only to check in the files you wanted by using .gitigonore. Furthermore, use SSH instead of HTTPS, so you don't need to log in every time you push or pull.
How to Use Global Variable among ES6 Modules
Adam C. |
ES6 Modules give us a lot of freedom, so then we can write functions in a different module. An ES6 module is a file containing JS code, and we can import and export it in modules. In this article, l will show you how to share the variables among ES6 Modules, which I think it's an alternate way to do closure in ES6 Modules.
How to Connect to Vacation House's Wifi
Adam C. |
Learning how to connect to some public Wifi, like Vacation House/Library/Hotel, etc. which requires login / accepting Terms and Conditions. This usually is straightforward, because most phones will open the page automatically after entering the Wifi password, but on some devices, it may drive you crazy, like Macbook or Kindle Fire tablet. This post will show you how to get to the Wifi login page.
How to Change the Version of Node.js in VS Code
Adam C. |
NVM is a great tool to manage different version of NodeJS installed on your computer. Either you want to upgrade to the latest NodeJS, or just switch from different versions as project needed, it comes in handy. But sometime it would be confused that you already use the version you pick in nvm, but VS Code is still using a different version. It's easy to fix only if you know how to.
Finally We Fixed "Failed to Fetch" Error
Adam C. |
In this article, we learned how to fix the 'failed to fetch' error from API-Gateway in our AWS Lambda Serverless Framework. The root cause is ended up to be the expired AWS Cognito Access/ID tokens. We were able to fix this by utilizing the Apollo Error Link to replace the old token with the refreshed one, and then retry the request.
How to Migrate MongoDB to a New Server
Adam C. |
Recently I migrated MongoDB (over 2GB) from a cheap server hosted on Hudson Valley Host to a better server hosted on Digital Ocean to improve the performance. In this article, I would like to write down some notes for this process.
Fix Serverless Build Errors on AWS Lambda
Adam C. |
We have a serverless application running on AWS Lambda. Recently, we saw some warnings/errors in the AWS CodeBuild log as below, although the application is successfully built: provider.apiGateway.shouldStartNameWithService and gypErr. In the article, we will explain the issues and solutions.
Code Splitting Make a Huge Different
Adam C. |
React is usually used to build a single page application, which means you only load the application code (HTML, CSS, Javascript) once. It works perfectly for a small application, but for a complex application, to load all Javascript code into a bundle (i.e., main.js) could cause the initial page loading to become very slow. So when you find that your app has a performance issue, the first thing you should try is code-splitting.
NPM Update is Painful
Adam C. |
Updating NPM seems to be very easy. Running 'ncu -u' followed by 'npm install', we can have all our dependencies up to date. However, updating packages without checking breaking changes is very dangerous. I could not find any easy solution, but suggest doing this often and testing your app thoroughly.
How to Import JSON into MongoDB using NoSQLBooster
Adam C. |
NoSQLBooster is probably the best free MongoDB GUI tool. We have been used to import CSV data into a MongoDB collection for a while, which works very well. But we got the error when importing JSON data. That might sound very weird, doesn't it? It ends up because we did not provide the "correct" JSON format. Let's see what JSON format to make NoSQLBooster happy.
Migrating to Apollo Client 3.0
Adam C. |
Apollo Client 3.0 includes some breaking changes, but since the Apollo Boost project is now retired, and React-Apollo has been deprecated, it's time to migrate. But Apollo Client 3.0 is mainly focusing on Hooks when being used in the React project. If your React project is not Hook ready yet, you may be wondering it's possible to use Apollo Client 3 with React Class Components or not. In short, the answer is YES.
Save JWT To HttpOnly Cookie Instead of LocalStorage
Adam C. |
NextFeathers uses JSON web token (JWT) for authentication when calling the Restful API implemented by FeathersJS. The JWT token was simply saved in the browser's localStorage and removed when the user is logged out. Many people said this is very bad because the hacker could run Javascript via what so-called XSS on your website, and read the data from localStorage. Personally, I kinda against this because it's unlikely happened, and as I know that is how AWS-amplify works by default. But there is indeed a risk, so I would like to fix it.
Convert CSV File to Restful API Using FeathersJS
Adam C. |
In this article, we will learn how to easily convert CSV files into a Restful API using FeathersJS Command Line and MongoDB. We will also learn how to cast data type using FeatherJS hook.