3

So I'm trying to build a command line tool using node.js but am running into problems trying to run the tool. Here's the simple code that I have.

src/main.js

#!/usr/bin/env node
'use strict';

(function main() {
    console.log('Hello World!');
})();

and in my packages.json I have this added

"bin": {
    "test": "./src/main.js"
 }

But when I try and execute test from the command line I get a Microsoft JScript compilation error at line 1 char 1 invalid character code 800A03F6.

Any ideas what I might be missing? Thanks :)

2
  • How do you run this ? Seems like Windows Scripting Host processes your code, not Node Commented May 24, 2018 at 2:11
  • I just type test into the command line Commented May 24, 2018 at 2:13

1 Answer 1

4

Found the information from this tutorial

npm install -g

test

Hello, world!

Did you try to install it before running it?

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

3 Comments

Oh nice thanks! Using npm link during development instead of npm install -g will be great too
Do mark it as answer if it correctly answered your question yea, cheers
Doesn't work for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.