0

I am building a node js command line pacakge, and when I am linking one of my projects to the command line project when I am trying to use the command, it's trying to open it like a js file on windows, and not as a node js application.

this is the command line project package.json:

{
  "name": "sitemap-generator",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "commander": "^2.19.0",
    "esm": "^3.0.84",
    "fs": "0.0.1-security"
  },
  "bin": {
    "smg": "./cli.js"
  },
  "engines": {
    "node": ">=9.5"
  }
}

and the index.js file:

'use strict';

const program = require('commander');

program
    .version('0.0.1')
    .description('Contact management system');

program.parse(process.argv);

the error:

enter image description here

2 Answers 2

1

I believe the command you want to run is node index.js [arguments] instead of opening the js file directly.

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

4 Comments

but i am trying to run this command throw another project of me, that i linked via git link.
take the assumption that I am an experienced javascript developer
In that case I'd recommend that you export the function you're trying to call from your index.js in your module.exports and run the function directly from the app that's calling this.
so my index.js is now module.exports = require("./bin/cli");, and this isnt helping.
1

The answer is to add the following line to the top of the cli.js file: #!/usr/bin/env node

so the file looks like this:

#!/usr/bin/env node

const program = require('commander');

program
    .version('0.0.1')
    .description('Contact management system');

program.parse(process.argv);

@mklement0 - #!/usr/bin/env node is an instance of a shebang line...

Comments

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.