Use it

in terminal

Once installed, call it typing jsrownum or jrn in your terminal, like this:

# or

or specify a glob pointing to some js files:

jsrownum "folder/*.js"
# or
jrn "folder/*.js"

If jsrownum is too long, you can also type jrn; we wired up that as an alternative.

Quick Take

It updates each console.log in your .js files...


// something on row 1
// something on row 2
console.log('000 var = ' + var); // row 3
// ^^^


// ...
console.log('003 var = ' + var);
// ^^^

Because it's on row 3. If you're not using console.log, and are using for example log(), put that under "-t" flag:

jrn -t "log"

or if specifying paths,

jrn "folder/*.js" -t "log"


What it does

First, it depends, did you specify a path or not.

  • If you did, for example, jsrownum "folder/*.js" it will process that file (or expand glob into a list of files).
  • If you didn't, just typed jsrownum, it will use the current folder where it was called from and look for files in this order:
  1. ./src/main.js
  2. ./main.js
  3. ./cli.js
  4. ./index.js
  5. ./src/index.js

Once it picks the file, it will look for console.log statements, and replace the first chunk of an uninterrupted sequence of numbers with a number of a row it sits.

For exampe, on row number 55 there's a console.log("045 var = " + var). It will replace 045 with 055.


The default padding is three characters, but you can override it, see the optional flags table below.

console.logs help to troubleshoot the code. These days Rollup builds are standard — having a source in ES Modules (and pointing unit tests to it) and using that source to build three types of applications: 1. ESM (same as source); 2. UMD (minified, for browsers and; 3. Common JS — transpiled to ES5, suitable for older platforms.

Now, you can use Rollup to remove comments and console.logs automatically when producing production builds. During development builds, you can use CLI flags to skip console.log removal. This way, you get all the goodness of console.logs in the terminal, and there's no risk that they will spill into production.


Once installed globally, type in your terminal: jsrownum OR type jrn.

If you won't pass any glob file/folder pattern or patterns, for example, just type jrn, it will look for the following files in this priority order:

  1. ./src/main.js
  2. ./main.js
  3. ./cli.js
  4. ./index.js
  5. ./src/index.js

If you will pass some globs, for example:

jrn "src/*.js"
jsrownum --pad="4" "dist/**/*.js test/ index.js"
jrn "test1.js test2.js" -p 2 will expand the globs and catch all .js files in the folders you specified and process them.

Optionally, you can pass the options, which match the API:

CLI flag For example, What it does
-p or --pad jsrownum -p 3 or jrn --pad="4" Lets you set the row number padding. For example, console.log statement on row 3 with padding set to 4 would get 0003 added. Row 99 with padding of 1 would be still 99.
-t or --trigger jrn -t "log" Lets you change from "console.log" to any function's name, for example update "001" in log(\001 z = ${z}`);`

Using multiple flags

Command line applications have few rules. First, if you want to pass multiple values to a certain flag, put -* or --***** for each value:


jrn -f "log" -f "yo"


jrn -f "log" "yo"


If you want to put double quotes, escape it like using left slash:

jrn -f "zzz\"yyy"

A nifty setup idea

We set up an alias for jsrownum, to piggyback on some common command we run often. For example, git add . - this way all row numbers are processed automatically without any hassle.


See it in the monorepo opens in a new tab, on GitHub.


To report bugs or request features or assistance, raise an issue on GitHub opens in a new tab.

Any code contributions welcome! All Pull Requests will be dealt promptly.


MIT opens in a new tab

Copyright © 2010–2021 Roy Revelt and other contributors

Related packages:

📦 js-row-num 5.0.1
Update all row numbers in all console.logs in JS code
📦 json-comb 0.6.1
Command line app to manage sets of JSON files
📦 json-comb-core 7.0.1
The inner core of json-comb
📦 json-variables 11.0.1
Resolves custom-marked, cross-referenced paths in parsed JSON
📦 json-sort-cli 2.0.1
Command line app to deep sort JSON files, retains package.json special key order