
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A CLI tool to automatically remove all console.* statements (log, warn, error, etc.) from JavaScript and TypeScript code.
Clean your code before production. No more forgotten
console.logs in your deployed apps.
console.* calls using AST (Abstract Syntax Tree)console statements.js and .ts files out of the boxYou can install the package locally in your projects depending on your use case.
npm install cleansole
npm i cleansole
Syntax:
npx cleansole <path>
| Argument | Description |
|---|---|
<path> | Path to a JavaScript/TypeScript file or a directory |
Examples:
npx cleansole test.js
npx cleansole test.js test1.ts
npx cleansole --warn --error test.js test1.ts
npx cleansole ./folder-name
npx cleansole ./main-folder/inside-folder/test.js
🔒 Your files will be updated in-place, removing all console calls. Always version your code or back up before batch operations.
Instead of using risky regular expressions to remove console.log statements, cleansole uses a safe and robust AST-based approach with Babel.
1. Parsing the Source Code
Using @babel/parser, each file is parsed into an Abstract Syntax Tree (AST). This tree represents your code structure in a programmable format.
const ast = parser.parse(code, {
sourceType: "module",
plugins: ["jsx", "typescript"]
});
2. Traversing the AST
We walk through the AST using @babel/traverse to find:
console.log(...)
console.warn(...)
console.error(...)
The logic looks for:
ExpressionStatementsconsole and a valid method like log, warn, etc.if (
t.isExpressionStatement(path.node) &&
t.isMemberExpression(path.node.expression) &&
path.node.expression.object.name === 'console'
) {
path.remove();
}
3. Generating Cleaned Code
After modifying the AST (removing console.* calls), the cleaned code is generated using @babel/generator.
const output = generate(ast, {}, code);
4. Writing to File
The updated source code is written back to the same file using fs.writeFileSync.
cleansole/
├── index.js # CLI entry point
├── test.js # Sample file
├── package.json
├── node_modules
└── lib/
└── clean.js # Console cleanup logic lives here
The tool removes all of the following:
console.log()console.warn()console.error()console.debug()console.info()console.trace()Node.js (https://nodejs.org/en)@babel/parser (https://babeljs.io/)@babel/traverse (https://babeljs.io/)@babel/generator (https://babeljs.io/)fs / path modules (https://nodejs.org/en)Made with ❤️ by [https://github.com/just-bk] — feedback welcome!
FAQs
CLI to remove all console statements from JS/TS files
We found that cleansole demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.