node.js - How do I write a shell script using node to run multiple javascript files one after the other? -
i want write .sh file run multiple javascript files.
i know need following lines:
#!/usr/bin/env node chmod u+x ./a/file1.js ./a/file2.js
is correct put 2 .js files 1 after other? need file1.js execute first , file2.js because of functions file2.js need information outputted file1.js.
i'm bit confused difference between #!/usr/bin/env node , #!/usr/bin/env bash. still able run .js files bash?
#!/usr/bin/env node
sets environment node.js javascript environment.
for example if create simple script test.js
following content:
#!/usr/bin/env node // we're in javascript! var d = new date(); console.log('current time: ' + d);
afterwards make executable:
$ chmod u+x test.js
then can execute in shell:
$ test.js current time: sun nov 13 2016 07:14:15 gmt+0000 (gmt)
the file extension doesn't matter:
$ mv test.js test.sh $ test.sh current time: sun nov 13 2016 07:15:05 gmt+0000 (gmt)
if don't want change javascript files become shell scripts can run them shell script using node.
tasks.sh:
#!/bin/sh node ./a/file1.js node ./a/file2.js
afterwards make executable , run it:
$ chmod u+x tasks.sh $ tasks.sh
Comments
Post a Comment