DEV Community

Cover image for Day 3: JS Scripts πŸš€
Valeria
Valeria

Posted on

3

Day 3: JS Scripts πŸš€

I like JavaScript and I don't like bash! And today I'd like to share with you a tool that allows me to do less of the latter: zx.

There are several ways to install it, with Deno you could do it like so:

deno install --global -A npm:zx
Enter fullscreen mode Exit fullscreen mode

Create a script, e.g. list.ts:

#!/usr/bin/env zx
import { $ } from 'npm:zx'

const list = await $`ls`
console.log(list)
Enter fullscreen mode Exit fullscreen mode

Allow execution as a script:

chmod +x list.ts
Enter fullscreen mode Exit fullscreen mode

And, finally, run it:

./list.ts
Enter fullscreen mode Exit fullscreen mode

Process output with files list

Isn't it awesome?! You can use any command available on your machine, check this example out:

#!/usr/bin/env zx

await $`cat package.json | grep name`

const branch = await $`git branch --show-current`
await $`dep deploy --branch=${branch}`

await Promise.all([
  $`sleep 1; echo 1`,
  $`sleep 2; echo 2`,
  $`sleep 3; echo 3`,
])

const name = 'foo bar'
await $`mkdir /tmp/${name}`
Enter fullscreen mode Exit fullscreen mode

And, as any other package, you could use zx as a library. Imagine all the cool things you could build!

Liked the content and would love to have more of it all year long?

Buy Me A Coffee

Image of Timescale

πŸš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsβ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more β†’

Top comments (0)

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay