Webux Lab - Blog
Webux Lab Logo

Webux Lab

By Studio Webux

Search

By Tommy Gingras

Last update 2023-04-23

NodeJS

NodeJS and commands that I often use

Call function in a JS script with parameters directly with bash

node -e 'require("./handler.js").handler({"body":{"foo":"bar"}}}, null)'

Automate a process using PM2

  1. Create a js script
console.log("Bonjour", new Date());
  1. Install pm2 and launch the task
npm i -g pm2
pm2 start task.js --no-autorestart --cron-restart="* * * * *"

Install tools using pnpm on for different architecture

Useful when you want to build npm dependencies for a different OS/platform (e.g ARM vs AMD)

pnpm install --config.platform=linux --config.arch=x64 sharp

This command is the equivalent when doing (Directly with npm)

npm install --platform=... --arch=... --arm-version=... sharp

Source: https://sharp.pixelplumbing.com/install

I needed that approach few times since I work with AWS and Lambdas (x86).  Since Mac M1 (ARM) I have a bunch of issues and weird behaviours to deploy to AWS Lambda using Serverless Framework Most of the time this is due to incompatible dependencies build. The other way to fix once and for all, is to use Docker. Give it a try and you will see why I'm using this approach instead.

Here is a small list of software that I had issues:

  • sharp
  • puppeteer
  • ffmpeg
  • In summary, everything that needs to build binaries from a specific system