0

Im following along with a nodejs book node.js the right way and im stuck when trying to execute this command. I changed #!/usr/bin/env to #!/usr/bin/node because env wasn't even a folder for me and node.js is in the node folder I believe. Im running ubuntu 14.04. Whats the fix? I have couchdb running in the background if that matters. Thanks

ryan@Ryan:~/Documents/code/databases$ ./dbcli.js

module.js:340
    throw err;
          ^
Error: Cannot find module '/home/ryan/Documents/code/databases/node --harmony'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

and heres the program

#!/usr/bin/node node --harmony
/***
 * Excerpted from "Node.js the Right Way",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/jwnode for more book information.
***/
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));
  }
});
Ryan
  • 29
  • 8
  • Posting a small code snippet from `dbcli.js` could help inform an answer, so it might be worth adding in – Mahout Aug 21 '15 at 22:19
  • What happens when you just type `node -v` at the command prompt? Does it run node and show you the version? Is it in your path? – jfriend00 Aug 21 '15 at 22:38
  • v0.10.40 Not sure what you mean by path, but yea i have it installed. – Ryan Aug 21 '15 at 22:39
  • And, last I checked, you can't put `#!/usr/bin/node node --harmony` in a .js file that you pass to node becaus that isn't valid Javascript. You can remove that line and run the .js file manually by just typing this: `node --harmony dbcli.js`. – jfriend00 Aug 21 '15 at 22:40
  • ill try that! sounds right – Ryan Aug 21 '15 at 22:41
  • ayyyyyy, we good we good! thanks so much man! yup, simple fix – Ryan Aug 21 '15 at 22:42
  • so the book screwed up , not me! – Ryan Aug 21 '15 at 22:43
  • Telling someone wondering why the shebang is not working that the "solution" is not to use it is, well, uhhh. –  Aug 22 '15 at 06:07

2 Answers2

1

Making my comment into an answer since it solved your problem:

Last I checked, you can't put #!/usr/bin/node node --harmony in a .js file that you pass to node becaus that isn't valid Javascript. You can remove that line and run the .js file manually by just typing this:

node --harmony dbcli.js

FYI, it looks like it's possible to do what you were trying to do, but you weren't using the proper syntax since you were trying to run node node. See this answer.

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

The shebang line should be

#!/usr/bin/node --harmony

With your current line, you are telling node to run the module called "node".