node.js - How can I run a JavaScript automatically on a command-line? -


i have simple javascript myscript.js code below;

var printer = function(somestring){     console.log(somestring); }  printer("this printed on console."); 

i'm on windows 10 , need able call myscript.js on command prompt , have code executed without doing node myscript.js. there way set things command prompt or powershell can automatically call nodejs or other javascript engine?

if windows can run normal shell scripts on command line can add shebang line node script shell scripts. example:

#!/usr/bin/env node // node code here 

also can try configure node invoked files .js extension can security hazard because may execute arbitrary code clocking on javascript files may have downloaded on system wouldn't recommend that.

another alternative make bat script node app:

example.bat:

node example.js 

example.js:

// node script 

that able run just:

example 

on command line.


Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -