pdoherty926 pdoherty926 - 1 month ago 5
Node.js Question

Unable to run Node script from $PATH

My Node (6.9.0) script runs without issue when I'm in the module directory and use

node bin/index.js
.

However, when I try to run it from $PATH (either via creating a
bin
entry in package.json and using
npm -g install .
or
npm link
), I'm met with the following:

/home/peter/.nvm/versions/node/v6.9.0/bin/react-render-server: line 1: global.__RWR_ENV__: command not found
/home/peter/.nvm/versions/node/v6.9.0/bin/react-render-server: line 2: syntax error near unexpected token `'babel-core/register''
/home/peter/.nvm/versions/node/v6.9.0/bin/react-render-server: line 2: `require('babel-core/register');'

Answer

You'll need to include #!/usr/bin/env node at the top of your node script. See this post What does "#!/bin/env" mean (at the top of a node.js script)?