Skip to main content

Claude/ChatGPT Prompt to Port a Node.js Script to a Rust CLI

Prompt to port a Node.js script to a fast single-binary Rust CLI with clap, anyhow, and tracing, keeping the same interface plus real benchmarks.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt ports a Node.js script to a single-binary Rust CLI that preserves the original interface and behaviour. It frames the model as a senior Rust engineer porting tooling and returns working code, not pseudocode. It asks for six things: a clap CLI matching the original flags and output exactly, anyhow error handling with matching exit codes, tracing-based logging with a --verbose flag, tokio only if the I/O genuinely needs async, a Cargo.toml and release setup producing a single binary, and an honest benchmark comparing Node.js to Rust.

Four variables drive the port. [behaviour] is the behaviour to preserve, like exiting non-zero on any failed file. [io_profile] decides whether async is warranted — if it's not, the port stays synchronous and simple. [distribution] sets the build targets for the single binary. [script] is the Node.js source being converted. The guard against gold-plating is deliberate: stay synchronous unless the I/O demands async, and keep the benchmark honest — if Rust isn't meaningfully faster, that's a real result.

When to use it

  • You have a Node.js script that runs constantly and want faster startup
  • You want to ship a tool as a single binary with no runtime dependency
  • You need the Rust version to match the original flags and output exactly
  • You want exit codes that mirror the Node.js behaviour
  • You want an honest benchmark to decide if the port is worth it
  • You want to avoid over-engineering with async you don't need

Example output

You get a full Cargo.toml, src/main.rs, and benchmark notes. The CLI matches the original's flags, args, and output; errors use anyhow with exit codes mirroring the Node.js script's behaviour; logging runs through tracing with a --verbose flag; tokio appears only if the I/O profile genuinely needs it; the build setup produces a single binary for your distribution targets; and the benchmark compares Node.js versus Rust on representative input with the method stated.

Pro tips

  • Keep it synchronous unless [io_profile] truly demands async; gold-plating with tokio adds complexity for no gain on file-heavy, network-free work
  • Paste the complete Node.js source into [script]; the more accurately it sees the original, the closer the behaviour match
  • Be precise about [behaviour], especially exit-code semantics like exiting non-zero on any failed file, so the port matches under failure
  • Make the benchmark honest; if Rust isn't meaningfully faster for your workload, that's a real result, not a failure of the port
  • Set [distribution] to your real targets so the release build produces binaries for the platforms you actually deploy to
  • Compare the Rust output against the Node.js output on the same input to confirm the interface matches exactly
  • State the benchmark method explicitly (input size, machine, warmup) so the Node.js versus Rust comparison is reproducible rather than a one-off anecdote

Frequently Asked Questions

Will the Rust CLI behave exactly like my Node.js script?
It is built to match the original flags, args, output, and exit codes, with special attention to whatever you specify in `[behaviour]`. Paste the full `[script]` and verify outputs side by side, since edge cases can still differ and need checking.
Does it always use async Rust?
No, and that is intentional. It uses tokio only if `[io_profile]` genuinely needs async I/O; otherwise it stays synchronous and simple. Adding async to file-heavy, network-free tooling is gold-plating that adds complexity without real benefit.
Is Rust guaranteed to be faster than the Node.js version?
No. The prompt asks for an honest benchmark with the method stated, and if Rust is not meaningfully faster for your workload, that is a legitimate result. Startup time and single-binary distribution are often the bigger wins, not raw throughput.
What should I paste into the script variable?
Paste the complete Node.js source you want ported into `[script]`. The more fully the model sees the original logic, flags, and error handling, the more accurately the Rust CLI can mirror its interface and behaviour.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Rust & Go Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support