0

How do you create a console app that you can run by a name instead of using node and a .js file to start the app?

Instead of... $ node myapp.js --out ./folder/

Can I... $ myapp --out ./folder/

1

1 Answer 1

0

You can use the bin option in your package.json file to make your script executable. From the documentation for package.json:

A lot of packages have one or more executable files that they'd like to install into the PATH. npm makes this pretty easy (in fact, it uses this feature to install the "npm" executable.)

To use this, supply a bin field in your package.json which is a map of command name to local file name. On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.

Click the link and search for bin: https://www.npmjs.org/doc/json.html for more info.

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

4 Comments

I suppose this allows to distribute your script. It doesn't help to create it.
what do you mean? If you specify the bin option, you can run npm install and then it will copy it into your PATH
Do you mean that npm will automatically create the file for the bin directory?
Yes, that's how it works. It will create a symlink inside bin. Refer to that link for more info.

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.