1

I want to be able to install my package through npm and then run app.js with a custom command without using npm start. I have looked around the web and many examples show adding a line in scripts in the package.json file, but all of these require it to be run using npm start. Is there a way to execute a .js file with node using a custom command e.g. importer --file?

4
  • 1
    You could always run node app.js Commented Jul 4, 2018 at 20:12
  • What do you mean by custom command? Commented Jul 4, 2018 at 20:12
  • I want to publish the package so it can be used from the command line e.g. by using importer -file Commented Jul 4, 2018 at 20:13
  • Does your package.json have the correct bin entry, as described here in the docs? I believe if you install the package globally this executable name automatically gets added to the same directory where npm and npx are (they are done using this same method), and that directory should be in your PATH. Commented Jul 4, 2018 at 20:50

1 Answer 1

1

Before publishing your package, you'll need to have a package.json file with at least the following:

{ "name": "importer", "version": "0.0.1", "bin": "./importer.js" }

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

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.