How to use the hygen code generator

How to use the Hygen code generator

There are platforms that list thousands of generators namely yeoman but often you will need something simple and custom. The alternative is to use Hygen for generating custom project sections.

Hygen is using javascript for prompt and EJS for templating but is fully capable of generating code in any language.
Photo by Bank Phrom on Unsplash

Start with creating the project

Go to and create a new node project

Saving will create your personal copy

Then you can open a new terminal.

1. Save 2. Hide browser 3.add new terminal

Initialize Hygen generator

Write into the following command into the terminal.

npx hygen init self

you should see an output like this.

npx hygen init self

Now we have a generator that will be used to create other generators

You can generate meme as well

Generate a with-prompt generator

We will be using prompt to ask questions in the console. See examples of prompts using enquirer.

npx hygen generator with-prompt readme

Now we can change the template files

Update _templates/readme/with-prompt/hello.ejs.t to:

# <%= name %>
<%= message %>

Update _templates/readme/with-prompt/prompt.js to:

Run the generator and create

Run following command in Terminal

npx hygen readme with-prompt
The output of the generated file

Run a script in from template frontmatter

Update _templates/readme/with-prompt/hello.ejs.t to:

sh: curl -s,macos,linux,windows,node,jetbrains,sublimetext,eclipse,netbeans,visualstudiocode > .gitignore
<%= message %>
# <%= name %>

The output of the shell script will create .gitignore file in your project. Curl will return it from API and pipe it to .gitignore.

Final project


The sky is the limit when using generators. Hygen is providing more options like injecting into existing files or running shell scripts, all the examples are in the documentation

Read more about generators in general in the previous article.

Improve your Javascript Developer Experience by generating code

👏Clap, 👂follow for more awesome 💟#Javascript and ⚛️#automatization content.

How to use the hygen code generator was originally published in ableneo Technology on Medium, where people are continuing the conversation by highlighting and responding to this story.