How do you run JavaScript script through the Terminal?

前端 未结 16 1761
离开以前
离开以前 2020-12-02 04:00

For instance, if you were to run a Python script you would type python filename.py or if you wanted to run a C program make filename then ./ filename

16条回答
  •  离开以前
    2020-12-02 04:17

    You can use a shebang file :

    script.js

    #!/usr/bin/env node
    console.log('Hello terminal');
    

    And run it

    ./script.js
    

    Don't forget to chmod +x script.js

提交回复
热议问题