Skip to main content

Migrate a Node.js project from NPM to PNPM

· One min read
Daniel G
Developer

Install pnpm:

# on Mac
❯ brew install pnpm

# with node.js installed
npm install -g pnpm

Steps


# Remove existing dependencies and the NPM lock file
rm -rf node_modules package-lock.json

# Install dependencies
pnpm install

Update Scripts

  • npm run test => pnpm test
  • npm start => pnpm start
  • npx prisma migrate dev --name "$1" --schema=app/prisma/schema.prisma => pnpm dlx prisma migrate dev --name "$1" --schema=app/prisma/schema.prisma

Update Dockerfile

Install PNPM and migrate related commands:

RUN npm install -g pnpm@latest-10

RUN pnpm install

RUN pnpm dlx prisma generate --schema=app/prisma/schema.prisma

CMD ["pnpm", "start"]

Update CI/CD

  • Use pnpm/action-setup
  • Use cache to reduce installation time
on:
- push
- pull_request
jobs:
deploy:
name: Deploy to AWS ECS - ${{ inputs.environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
run_install: false

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22.x"
cache: "pnpm"

References

Enable/disable the in-editor query of Intellij database

· One min read
Daniel G
Developer

I don't how it happens and I definitely didn't enable it explicit, the query results are shown in a floating window just after the query:

In-editor results

Previous the query results are shown in the fixed Services window:

Non in-editor results

I cannot find a way to turn it off in Intellij Idea settings and in the floating window settings.

Actually there is a switch called In-Editor Results in each query editor:

In-editor switch


References

The apps (on Mac) that I cannot live without

· One min read
Daniel G
Developer

Maccy

Maccy is a lightweight clipboard manager for macOS. It keeps the history of what you copy and lets you quickly navigate, search, and use previous clipboard contents.

Project site: https://github.com/p0deje/Maccy.

Features:

  • Open source and free
  • Keyboard-first
  • Lightweight and fast
  • Secure and private
  • Options to past automatically and paste without formatting
  • It can ignore applications like password managers

Hammerspoon

It is an open source tool for powerful automation of OS X. You can write Lua scripts to control many aspects of your OS X environment.

I mainly use it to configure global shortcuts for applications (my config).

Project site: https://github.com/Hammerspoon/hammerspoon

Vim

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient.

I use Vim whenever possible, for example: VS Code (Cursor), Sublime Text, Intellij Idea etc (my config).

Project site: https://github.com/vim/vim

How to download all files in a S3 bucket folder

· One min read
Daniel G
Developer

Let's say we have a S3 bucket demo_bucket, and we have folder path under that bucket: public/emails/templates. I have 30 files under that path and I want to download all files. In the AWS console, we can only download one file each time.

We can use the AWS CLI to download all the files:

aws s3 cp s3://demo_bucket/public/emails/templates/ .  --recursive

Process JSON data using `jq`

· 2 min read
Daniel G
Developer

JSON is a widely used exchange format and we have many opportunities to process JSON data in daily work.

jq is a flexible and popular command-line JSON processor. It's very helpful to transform JSON data.

Here are my practical examples using jq to process JSON data.

The example JSON data (input.json) is like:

[
{
"id": "0c1160b4-42c9-4aee-8287-68b0cf03ebda",
"billingId": "54bdc967-0132-4cf2-9a9e-67d0230f7cce",
"requestBy": "6b303448-4010-4ab8-a3dc-30bbd4145475",
"paymentType": "DIRECT_DEBIT",
"createdAt": "2024-06-11T23:22:54.777Z",
"refundAmount": 29.9,
"refundDate": "2024-05-30",
"updatedAt": "2024-06-11T23:22:54.777Z"
},
{
"id": "4fa36c92-a1c1-44be-bd5e-f0697fd91420",
"billingId": "4f13d5f9-d0d9-470f-8e98-d5c6a37ac428",
"requestBy": "6b303448-4010-4ab8-a3dc-30bbd4145475",
"paymentType": "CREDIT_CARD",
"createdAt": "2024-06-11T23:22:54.777Z",
"memberId": "52dd5dfc-82d2-526f-b3ef-f0df008eb37a",
"refundAmount": 13.0,
"refundDate": "2024-05-30",
"updatedAt": "2024-06-11T23:22:54.777Z"
},
{
"id": "3ff9266a-18f6-4473-ac9c-ac99d28c608e",
"billingId": "4823b60d-79ca-411b-a993-9d9b3d4f2350",
"requestBy": "6b303448-4010-4ab8-a3dc-30bbd4145475",
"paymentType": "CREDIT_CARD",
"createdAt": "2024-05-11T23:22:54.777Z",
"memberId": "9f993c23-e3ab-4a65-93ed-5fe4c343843c",
"refundAmount": 38.0,
"refundDate": "2024-06-30",
"updatedAt": "2024-06-28T23:22:54.777Z"
}
]

Different ways to deploy an node.js application to AWS

· 5 min read
Daniel G
Developer

Discussion

We have a Node.js application providing REST and/or GraphQL APIs, which is part of the microservices architecture. What are the possible ways to deploy the application to AWS?

And what's the pros and cons for each approach?

Elastic BeanStalk

AWS Elastic Beanstalk is a Platform as a Service (PaaS) that makes it easy to deploy, manage, and scale web applications and services. It automatically handles the deployment, from capacity provisioning, load balancing, and auto-scaling to application health monitoring.

Pros:

  • Ease of Use: Simplifies deployment and management, ideal for those less familiar with AWS infrastructure.
  • Managed Service: Handles the underlying infrastructure, including servers, load balancers, and scaling.
  • Integration: Well-integrated with other AWS services.

Cons:

  • Limited Control: Less granular control over the underlying infrastructure compared to managing your own instances.
  • Cost: Can be more expensive than manually managing instances, depending on your application’s requirements and usage.

Use Case: Best for developers looking for a quick and easy way to deploy and manage applications without deep knowledge of AWS infrastructure.