I have node file whose name is author.js
which is present under import folder. How I run this file using the command : import author
please help me into this?
Asked
Active
Viewed 464 times
-1

Suraj Dalvi
- 988
- 1
- 20
- 34
-
1Don't quite understand what your problem is, you might want to reword it a bit. Just incase you are looking for the command for running nodeJS, `node author.js`. – Samuel Toh Sep 12 '16 at 07:04
-
Put your code in the question. Difficult to help without that! – ppeterka Sep 12 '16 at 07:06
-
I just want to run my node file with the custom command. To run node file we are using `node author.js` but if I want to use the custom command to run node file, My question similar to [How do I add a custom script to my package.json file that runs a javascript file?](http://stackoverflow.com/questions/36433461/how-do-i-add-a-custom-script-to-my-package-json-file-that-runs-a-javascript-file) but I can't able to understand please help me into this? – Suraj Dalvi Sep 12 '16 at 07:10
-
change environment variable settings to define your custom commands – Anmol Mittal Sep 12 '16 at 07:13
-
I don't really understand your question, maybe you could explain your problem better. Is your question: How can I run my author.js with via command line with the command `import author` instead of `node author.js`? Or is your problem that you don't know how to include author.js into your main.js or app.js or whatever. – Urknecht Sep 12 '16 at 07:29
1 Answers
1
I hope I understand this correctly, if you are looking to execute certain commands/functions that are in the author.js file via the terminal, the thing you are looking for is argv on the process object for passing in values from the terminal.
So for example in the terminal you type:
node author.js import authorName
And in your file you have a function that listens to the argv object
if(process.argv[2] == 'import'){
/* some function that does stuff with process.argv[3] value (authorName)*/
}
You would be able to run the function directly from the command line.
For more information on process.argv: https://nodejs.org/docs/latest/api/process.html#process_process_argv

Aldose
- 131
- 3