windows command line javascript

前端 未结 5 1753
小鲜肉
小鲜肉 2021-02-14 04:21

I\'m trying to run javascript from a windows command line via script

cscript //NoLogo test.js

However, I can\'t find any predefined objects which are av

5条回答
  •  北恋
    北恋 (楼主)
    2021-02-14 04:49

    This is a very outdated thread, many of the answers are incomplete and/or simply don't work. The way to run JS in shell (regardless if you're using windows or not), is to use Node.js. After you have installed Node, you use it from command line, like this:

    $ node
    > console.log('Hello, world');
    Hello, world
    undefined
    > .exit
    

    or from a file:

    $ cat hello.js
    #!/usr/bin/node
    console.log('Hello, world');
    
    $ ./hello.js
    Hello, world
    

    Or from node itself:

    $ node hello.js
    Hello, world
    

提交回复
热议问题