top of page
Search
  • Writer's pictureYun'Harla

Pre-processor Directives and more in Node.JS+


Node.JS is a staple for me in server-side development and general scripting in JavaScript. Having come from a C++ background, I've missed having pre-processor directives in JS. Hence, it is a delight when I find the defunct pre-processor.js by dcodeIO.


I enjoy mishmashing good things together. Thus, I've modded both Node.JS and pre-processor.js, and jammed them together with CoffeeScript and TypeScript transpilers : )


The result is Node.JS+ on GitHub. Enjoy!


What can it do?

  • D Script: use pre-processor directives in CJS scripts.

    • Common pre-processor directives like #define, #ifdef, etc. are supported as per pre-processor.js, but not fully like C++'s.

    • Crazy directives included. Like #cs, #ts to embed CS & TS code fragments respectively.

  • REPL mode for D Script, CoffeeScript and TypeScript.

    • E.g.: run 'node.exe --repl=cs' for CoffeeScript

      • Choice 'ds', 'cs' and 'ts' respectively.

    • Use editor mode (i.e. enter '.editor' to activate in REPL) to try out code blocks from DS, CS or TS. CTRL-D to exit editor mode.

  • Just for fun: Run directly: DS/CS/TS scripts.

    • Recognized by file extension; internally transpiled and run.

    • If you're looking for more robust (and production grade?) TS execution and REPL, look at ts-node.

    • Node.JS+'s support for CS & TS are achieved by jamming minified + browserified versions of CS & TS within Node.JS, without any additional optimizations.

      • Thus, Node.JS+ is probably way easier to maintain!

Why D?

Cos C, C++, D.


How Complex is (the additions to create) Node.JS+?

Actually pretty neat as it's only around a handful of modified files in the Node.JS corpus!


DS transpiler is pretty small, unlike the massive original Node.JS, and CS and TS transpilers. The only troublesome part is packaging CS, TS and glob into like minified one-liners to embed in Node easily, instead of having to figure out how to add over a hundred source files to Node.

  • Nope, actually the packaged CS takes up ~24 lines, TS ~33 lines, glob ~1 line : )

  • Done by a combo of browserify + minifyify, with some minor edits to suppress their (CLI) auto-execution upon load.

    • If anyone is interested, ask me.



Kudos to all the awesome folks who created Node.JS, pre-processor.js, et al.


3 views0 comments

Recent Posts

See All
Post: Blog2_Post
bottom of page