Crafting Prompts in Node.js/TypeScript with Structure

19.06.2025

I've been building stuff for a long time and I've realized that simplicity and structure goes a long way, especially when you’re doing your thing with large language models (LLMs) like ChatGPT or Gemini. 🤖

You ever prompt a model and notice it start's hullicating within the first 5 prompts? It started with a few questions, broken into a request including contexts from a bunch of random thoughts and ideas you have and BOOM, ChatGPT is spitting out a rap song when you're requesting a JSON reply. Lol I'm kidding, that doesn't happen. Close enough though.

So, here’s my take on building prompts in Node.js and TypeScript: keep it structured, keep it chainable, and don’t overthink it.

Why Bother Structuring Prompts?

  • Clarity: If you want the AI to give you solid responses, you gotta be clear. No one likes guessing games—not even a language model.
  • Reusability: Build little prompt pieces you can use again and again. Like LEGOs, but for your brain. Helps you keep your sanity too.
  • Maintainability: Speaking of sanity, when you come back to your code in six months, you’ll thank yourself for not making it a dumpster fire.

Meet littleprompt

littleprompt is a tiny, chainable library for Node.js/TypeScript I whipped up. It lets you build prompts step by step, adding instructions as you go. It’s not magic, but it makes life easier—especially if you’re a little neurodivergent like me and need things to be, well, not chaos.

Install It

npm install littleprompt

Building Prompts: The Chainable Way

Forget string soup. Here’s how I build prompts:

import prompt from "littleprompt";

const myPrompt = prompt
  .system({ type: "engineer", name: "Johnson" })
  .concise()
  .truthful()
  .system("is funny")
  .system({ responseType: "structuredJSON" })
  .user("What are the first 3 steps to making a website?");

console.log(myPrompt.build());

What you get:

System: 
  Your name: Johnson <--- Use this name at all times
  Role: Engineer
  Context of role:
    An engineer is a professional who applies scientific and mathematical principles to design, develop, and innovate solutions to practical problems. Engineers are involved in inventing, designing and maintaining a variety of machines, structures and data systems. They are experts in their fields, creating and innovating constantly. Engineers use their expertise in various branches of engineering, such as civil, mechanical, electrical, chemical, or software engineering, to create, improve, and maintain systems, structures, processes, and technologies.
  Instruction: Your answers must be concise. If you do not know the answer, say so. 
  Instruction: Your personality is funny. 
  Response Type: You must structure your response as a JSON data type.
  JSON Response Structure: {}

User: What are the first 3 steps to making a website?

The response is structured, clear, and ready to go. You can easily tweak the system instructions or user questions without rewriting everything.

{
  "step_1": "Define purpose and target audience — unless you enjoy building aimless digital sandcastles.",
  "step_2": "Choose a domain name and web host — think of it as naming your baby and finding it a cozy crib on the internet.",
  "step_3": "Design layout and structure using HTML/CSS — aka telling your site not to look like it time-traveled from 1997."
}

Stuff That Makes Life Easier

1. Stack System Instructions

Add as many as you want, in whatever order makes sense:

prompt
  .system("You are a helpful assistant.")
  .system({ persona: "Shakespearean poet", mood: "dramatic" });

2. User Questions

Set the user’s question or problem. Simple:

prompt
  .system("You are a world-class chef.")
  .user("How do I make a perfect omelette?");

3. One-Liner Modifiers

Handy shortcuts for common stuff:

  • .concise(): Short and sweet.
  • .detailed(): Go deep.
  • .truthful(): Admit when you don’t know.
  • .json(schema): Ask for a JSON response, with or without a schema.
  • .mood(feeling): Set the vibe, e.g., .mood("funny").
  • .expert(field): Be the expert, e.g., .expert("quantum physics").

4. Reusable Personas

Make little prompt factories for consistent vibes:

import prompt, { type Prompt } from "littleprompt";

const GrumpyReviewer = () => {
  return prompt
    .system({ persona: "Senior Engineer", role: "Code Reviewer" })
    .mood("incredibly grumpy")
    .concise();
};

const reviewPrompt = GrumpyReviewer()
  .user("Please review my amazing new function that sorts an array using bubble sort.")
  .build();

console.log(reviewPrompt);

Want to help improve littleprompt?

Check out the repo


Prompt engineering doesn’t have to be a mess. With a little structure and a chainable approach, you can build prompts that work, are easy to read, and don’t make you want to pull your hair out. If you’ve got questions or want to swap ideas, hit me up. Happy prompting! 🤏

Crafting Prompts in Node.js/TypeScript with Structure
More posts
or
View more posts on Medium
© 2025 Tony Rice