2

I am currently learning Node.JS on my windows machine. I've got my path set up and I've done quite a bit of development already (running all my scripts in cygwin). Finally, it's time for me to run these directly instead of calling 'node --harmony script.js'. The tutorial I'm using says to attach

#!usr/bin/env node --harmony

at the top of the file. Of course, this doesn't exactly work. My path variable says that the node program itself is in:

D:\NodeJS\

I've tried several different ways to use the Shebang to no avail. Every time I run the script, it announces:

./dbcli.js: line 1: #!D:/NodeJS/: no such file or directory

Anyone know how this is supposed to be used? Here's the code so far:

#!d:/NodeJS/node --harmony const request = require("request"), options = { method: process.argv[2] || 'GET', url: 'http://localhost:5984/' + (process.argv[3] || '') }; request(options, function (err, res, body) { if (err) { throw Error(err); } else { console.log(res.statusCode, JSON.parse(body)); } });

1

1 Answer 1

3

I found the answer and it turned out to be a bizarre one. Since I was developing in Visual Studio, the files were encoded as UTF-8 With BOM. As a result, it was getting a whole lot of nonsense in the file while attempting to run it directly.

The above code :

#!d:/NodeJS/node --harmony const request = require("request"), options = { method: process.argv[2] || 'GET', url: 'http://localhost:5984/' + (process.argv[3] || '') }; request(options, function (err, res, body) { if (err) { throw Error(err); } else { console.log(res.statusCode, JSON.parse(body)); } });

was exactly what I needed, but, since it was incorrectly encoded, it never worked. For the time being, I'm editing all scripts in Visual Studio and, for the ones I want to run directly, I'll open Notepad++ and switch over the encoding (until I find a better way).

Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't solve my problem. I get this error: 'myTool' is not recognized as an internal or external command, operable program or batch file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.