Member-only story
How to Write JavaScript Code to Create and Update a Changelog
No more generators, logs, or dependencies-now for JavaScript!

If you read my previous post about how to write a python script to create and update a changelog, or the post before that about writing a changelog script in bash, you might find this post interesting as well. The goal is to add support to multiple languages so developers don’t have to choose just one rather than they can choose the one that is most in line with the stack they’re currently using.
I’ve added JavaScript support to extend my original changelog script to engineers with a preference for JavaScript. You can now use the same script logic with JavaScript. If you’re a JS developer and want to add more customizations to your changelog creation/generation, you can do so more easily now with this added support.
Since it’s the same logic as my last two posts pertaining to Bash and Python, I won’t go too in depth in terms of functionality. Like the one on Python, this post will highlight syntactic differences.
First, create a changelog.js
file to run the script’s logic. You can make this file executable by running chmod +x changelog.js
. With this you will be able to run ./changelog.js
from your command line or include it in another script if that’s preferred by appending ./changelog.js
to it.
Next, we need our project’s version to be synced with our changelog. This is probably the most complicated part of the JavaScript code. You can do one of two things:
- Find a package (something like this maybe) that can be used to execute
git describe --long
in a JavaScript file. - Be a purist and do it all with your own code! If this is the route you’re going, we have a few steps.
First, we have to require
what is called child_process
and then run exec
on that child process. This method allows us to run commands in the console and buffer the output. Here is our first line of code.
const exec = require('child_process').exec;
Next, we need to write a function that runs a child execution that accepts "git describe --long"
as an argument, along with a callback function. Below is our function.