How do you run JavaScript script through the Terminal?

前端 未结 16 1773
离开以前
离开以前 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:33

    Technically, Node.js isn't proper JavaScript as we know it, since there isn't a Document Object Model (DOM). For instance, JavaScript scripts that run in the browser will not work. At all. The solution would be to run JavaScript with a headless browser. Fortunately there is a project still active: Mozilla Firefox has a headless mode.

    https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode

    $ /Applications/Firefox.app/Contents/MacOS/firefox -headless index.html
    *** You are running in headless mode.
    

提交回复
热议问题