shebang and node

197 views
Skip to first unread message

Urban Hafner

unread,
Jun 26, 2009, 11:04:12 AM6/26/09
to nod...@googlegroups.com
Hej all,

I don't have the setup to try this right now, but would something like
this work with current node?

#!/usr/bin/env node

// Code goes here

It would be nice to write everything in node itself (for example a
simple test runner for my library or a script to concatenate files).

Urban

Hagen

unread,
Jun 26, 2009, 11:11:03 AM6/26/09
to nodejs
it doesn't because # is not a comment symbol in javascript.

but that would be very cool indeed.

Urban Hafner

unread,
Jun 26, 2009, 11:13:54 AM6/26/09
to nod...@googlegroups.com
Hagen wrote:
> it doesn't because # is not a comment symbol in javascript.
>
> but that would be very cool indeed.

Ah, right. I forgot.

Urban

ryan dahl

unread,
Jun 26, 2009, 11:20:40 AM6/26/09
to nod...@googlegroups.com
That could be added easily - and I like the idea. Does anyone want to
give it a shot?

Look at the bottom of the file src/node.js - there it loads the
root_module, the module which was given on the command line. The file
can easily be scanned for a shebang (use a regexp) and removed before
compiling it (see node.compile() in node.Module.prototype.load()).

Tim Becker

unread,
Jun 26, 2009, 11:20:53 AM6/26/09
to nod...@googlegroups.com
Well, it shouldn't be a major undertaking to either add a `nodescript`
executable or a command line flag to indicate "ignore the first line
of the script if it's a #.
-tim

ru_ghetto

unread,
Jul 1, 2009, 2:42:53 AM7/1/09
to nodejs
I got around this one temporarily by having an executable bash script
evaluated a node script:

#!/bin/bash
eval "node server.node";

But yeah, regular expression to avoid this overhead would be sweet.

r...@tinyclouds.org

unread,
Aug 4, 2009, 4:54:30 AM8/4/09
to nodejs
Added in 6acac91.


self.target.__require = function (path) { return
self.newChild(path, {}); };
self.target.__include = function (path) { self.newChild(path,
self.target); };

+ // remove shebang
+ content = content.replace(/^\#\!.*/, '');
+
// create wrapper function
var wrapper = "function (__filename) { "+
" var onLoad; "+


Module loading isn't working yet from shebang scripts (unless they're
specified with a full path :P), but this handles the most trivial case
and encourages myself to finish it.


2009/6/26 ryan dahl <coldre...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages