First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js

Second, download and install The Mozilla group's Java based Javascript engine, Rhino. "Install" is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X). You can then run scripts with an invocation similar to this

java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js

Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one. For example

//original code    
(function() { ... js_beautify code ... }());

//new code
print(global.js_beautify(readFile(arguments[0])));

Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string. The function readFile accepts a file path string as an argument and returns the contents of that file.

You'd invoke the above something like

java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js

You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.

Answer from Alan Storm on Stack Overflow
🌐
Kali Linux Tools
en.kali.tools
JS Beautifier - Penetration Testing Tools
This little beautifier will reformat ... it supports improving the readability of CSS and HTML code. ... js-beautify – the main tool that improves the readability of JavaScript code, available in all JS Beautifier variants....
Main
JS Beautifier · JStillery · OllyDbg · Reverse · smali · TrID · UglifyJS · Valgrind · YARA · CaseFile · CutyCapt · dos2unix · Dradis · KeepNote · MagicTree · Metagoofil · Nipper-ng · pipal ·
All Programs
Tools for penetration testing and security audit · List of all available tools for penetration testing
Cheap VDS/VPS
Please click here if you are not redirected within a few seconds · You will be redirected in 3 seconds. If your browser does not automatically redirect you, please click here
🌐
GitHub
github.com › beautifier › js-beautify
GitHub - beautifier/js-beautify: Beautifier for javascript · GitHub
When installed globally, the beautifier provides an executable js-beautify script. The beautified result is sent to stdout unless otherwise configured. ... To use js-beautify as a node library (after install locally), import and call the appropriate ...
Starred by 9K users
Forked by 1.4K users
Languages   JavaScript 42.8% | HTML 35.9% | Python 15.5% | Mustache 2.7% | Shell 2.6% | Makefile 0.3% | CSS 0.2%
🌐
PyPI
pypi.org › project › jsbeautifier
jsbeautifier · PyPI
Beautify, unpack or deobfuscate JavaScript. Handles popular online obfuscators. ... Author: Liam Newman, Einar Lielmanis, et al. ... Download the file for your platform. If you're not sure which to choose, learn more about installing packages. ... Filter files by name, interpreter, ABI, and platform. If you're not sure about the file name format, learn more about wheel file names. ... Details for the file jsbeautifier...
      » pip install jsbeautifier
    
Published   Feb 27, 2025
Version   1.15.4
Top answer
1 of 10
76

First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js

Second, download and install The Mozilla group's Java based Javascript engine, Rhino. "Install" is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X). You can then run scripts with an invocation similar to this

java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js

Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one. For example

//original code    
(function() { ... js_beautify code ... }());

//new code
print(global.js_beautify(readFile(arguments[0])));

Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string. The function readFile accepts a file path string as an argument and returns the contents of that file.

You'd invoke the above something like

java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js

You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.

2 of 10
64

UPDATE April 2014:

The beautifier has been rewritten since I answered this in 2010. There is now a python module in there, an npm Package for nodejs, and the jar file is gone. Please read the project page on github.com.

Python style:

$ pip install jsbeautifier

NPM style:

$ npm -g install js-beautify

to use it (this will return the beatified js file on the terminal, the main file remains unchanged):

$ js-beautify file.js

To make the changes take effect on the file, you should use this command:

$ js-beautify -r file.js

Original answer

Adding to Answer of @Alan Storm

the command line beautifier based on http://jsbeautifier.org/ has gotten a bit easier to use, because it is now (alternatively) based on the V8 javascript engine (c++ code) instead of rhino (java-based JS engine, packaged as "js.jar"). So you can use V8 instead of rhino.

How to use:

download jsbeautifier.org zip file from http://github.com/einars/js-beautify/zipball/master

(this is a download URL linked to a zip file such as http://download.github.com/einars-js-beautify-10384df.zip)

old (no longer works, jar file is gone)

java -jar js.jar  name-of-script.js

new (alternative)

install/compile v8 lib FROM svn, see v8/README.txt in above-mentioned zip file

./jsbeautify somefile.js

-has slightly different command line options than the rhino version,

-and works great in Eclipse when configured as an "External Tool"

🌐
Kali Linux Tools
en.kali.tools › all
python-jsbeautifier
Home / Tools / python-jsbeautifier · List of all available tools for penetration testing. Description: JavaScript unobfuscator and beautifier · Category: reversing webapp · Version: 1.15.1 · WebSite: https://github.com/beautify-web/js-beautify · Last Updated: 2024-02-21 ·
🌐
Command Not Found
command-not-found.com › js-beautify
command-not-found.com – js-beautify
pacman -S node-js-beautify · Kali ... · Dockerfile · dockerfile.run/js-beautify · Beautify, unpack or deobfuscate JavaScript, leveraging popular online obfuscators....
🌐
Repology
repology.org › project › js-beautify › packages
js-beautify packages - Repology
Kali Linux Rolling main · 1.15.3 (1.15.3-1) Maintainer: havard.f.aasen@pfft.no · Category: misc · Link(s): Package pageok · Upstream homepageredir, no IPv6 · MacPorts · 1.15.4 · Summary: JS beautifier written in Python · Maintainer: nomaintainer@macports.org ·
🌐
JSON Formatter
jsonformatter.org › b9e805
kali
It uses $.parseJSON and JSON.stringify to beautify JSON easy for a human to read and analyze.
🌐
Beautifier
beautifier.io
Online JavaScript beautifier
Beautify JavaScript, JSON, React.js, HTML, CSS, SCSS, and SASS
Find elsewhere
🌐
Installati.one
installati.one › home › how to install jsbeautifier on kali linux
How To Install jsbeautifier on Kali Linux | Installati.one
June 1, 2023 - In this tutorial we learn how to install jsbeautifier on Kali Linux. jsbeautifier is JavaScript unobfuscator and beautifier
🌐
CodeBeautify
codebeautify.org › jsonviewer › cb977a95
kali
JSON Pretty Print / Pretty JSON Tool to Prettify JSON data.
🌐
OnWorks
onworks.net › home › software › linux › app js beautifier
JS Beautifier download for Linux
JS Beautifier download for Linux
JS Beautifier free download and run online in OnWorks over Linux online like Ubuntu, Fedora, Debian, Kali Linux
Rating: 4 ​
🌐
Arch Linux
aur.archlinux.org › packages › js-beautify
AUR (en) - js-beautify
Hi, could you add python-jsbeautifier to conflicts? Both have /usr/bin/js-beautify.
🌐
Miloserdov
miloserdov.org
JS Beautifier - Ethical hacking and penetration testing
Alex May 3, 2020 deobfuscation, JavaScript, JS Beautifier, JStillery, obfuscation, UglifyJS, web browsers, web-sites, webapps Reverse Engineering One Comment » · Telegram notifications about new articles on Miloserdov.org: t.me/miloserdov_org · Anonymity, data encryption and anti-forensics · Exploitation · Hardware · Improving security · Information Gathering · IT Forensics · Kali Linux ·
🌐
Installati.one
installati.one › home › how to install node-js-beautify on kali linux
How To Install node-js-beautify on Kali Linux | Installati.one
June 1, 2023 - In this tutorial we learn how to install node-js-beautify on Kali Linux. node-js-beautify is beautifier.io for node