TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Node.js PrePrcoessor – Extend Node.js to support macros/utility functions

2 pointsby bebrws9 months ago

2 comments

bebrws9 months ago
In this blog post, I show how I created a preprocessor that takes any line starting with “// log -” and creates a temporary intermediary file where those lines are replaced with console.log statements to print any expressions following “// log -”. This approach is useful in several ways. It’s easier than using console.log directly, and when run without using the preprocessor, these log lines are simply ignored. The entire setup is straightforward, utilizing a Node.js environment variable/option to run the preprocessor.
bearjaws9 months ago
You should look into how this is done at scale with something like Babel.<p>Babel parses JS into a AST (abstract syntax tree) and then lets you react to specific pieces of code.<p>Here is an example of the power of a tool like Babel: <a href="https:&#x2F;&#x2F;github.com&#x2F;christina-de-martinez&#x2F;babel-plugin-glowup-vibes&#x2F;tree&#x2F;main">https:&#x2F;&#x2F;github.com&#x2F;christina-de-martinez&#x2F;babel-plugin-glowup...</a>