In most cases, new files are not allowed to be executed. Make the JavaScript command-line file executable
COMMAND LINE FILE PEEK WINDOWS
In Windows, that line will just be ignored because it will be interpreted as a comment, but it has to be there because npm will read it on a Windows machine when the NodeJS command-line package is being installed. That way, we are telling *nix systems that the interpreter of our JavaScript file should be /usr/bin/env node which looks up for the locally-installed node executable. We do that by adding a shebang character sequence at the very top of our JavaScript file that looks as follow: Similar to other shell scripts, we want to make our JavaScript file executable by the locally installed program. Convert the JavaScript file into a NodeJS command-line script This a good practice because the name itself tells its purpose. The npm.js docs and popular NodeJS projects use to name JavaScript command-line file as cli.js.
![command line file peek command line file peek](https://cdn.ttgtmedia.com/rms/editorial/sWS-WindowServer2016-Fig4-060215_mobile.jpg)
More about that shortly first let us create a JavaScript file that will become the NodeJS command-line script.
![command line file peek command line file peek](https://imgcdn.maketecheasier.com/2018/08/linux-rename-files-featured.png)
That is fine in most cases, but a NodeJS command-line script is a regular JavaScript file, except that it contains a special shell-instruction. You may already know that we can execute a NodeJS script file by running: node script.js. Now that we have that let us create what will be our NodeJS command-line script. That is nothing new, nor specific to creating a NodeJS command-line package as it is the starting point of any NodeJS package.
![command line file peek command line file peek](https://documento.mx/img/detail/5c1154bd90969.jpg)
just a directory containing a package.json file. This guide will walk you through the creation, mapping, and linking of a NodeJS command-line script.īefore doing anything else, we need to create NodeJS package, i.e. Here is a concise guide on things we should do to create a NodeJS command-line package. Feeling inspired to create a NodeJS command-line script to solve a specific issue? Do you want to ship your command-line as an installable package? It should be simple, right? Fortunately, it is!