cs5117155
V2EX  ›  Node.js

终端命令下,什么命令 node 可以同时运行多个*.js 文件

  •  
  •   cs5117155 · Jan 21, 2022 · 10027 views
    This topic created in 1752 days ago, the information mentioned may be changed or developed.
    比如我文件夹下面有`a.js `,`b.js` ,`c.js`等等。每次运行都要 `node a.js & b.js & c.js`.
    有什么方法可以一次性执行当前文件夹下的所有 js 文件吗
    13 replies  •  2022-02-28 15:33:59 +08:00
    alphanow
    alphanow
    Jan 21, 2022
    1
    写个 index.js ,用 fs.readdir 把文件都读出来,然后再 map -> execFile
    以后 node .就行了
    momocraft
    momocraft
    Jan 21, 2022
    2
    xargs
    shyling
    shyling
    Jan 21, 2022
    3
    ls *.js | xargs -n 1 node
    b1eberg0n
    b1eberg0n
    Jan 21, 2022
    4
    concurrently
    ryncv
    ryncv
    Jan 21, 2022
    5
    ./start.sh (狗头
    ysc3839
    ysc3839
    Jan 21, 2022
    6
    find -name '*.js' -exec node {} \;
    akira
    akira
    Jan 21, 2022
    7
    手动写个脚本,需要增加或者删除的时候 手动处理。 生产环境不要偷懒
    xylxAdai
    xylxAdai
    Jan 21, 2022
    8
    shell 脚本
    cs5117155
    cs5117155
    OP
    Jan 21, 2022
    9
    @shyling 这个最方便,厉害
    jaredyam
    jaredyam
    Jan 22, 2022
    10
    我觉得#6 语义上更符合直觉,如果模式比较固定,放 Makefile 里岂不更好?
    wangtian2020
    wangtian2020
    Jan 28, 2022
    11
    用 nodejs 的 fs 模块读取文件夹下面的文件,生成 powershell 脚本,用 child_process 模块运行脚本
    能用 nodejs 写都能用 nodejs 写
    SoulGem
    SoulGem
    Feb 17, 2022
    12
    pm2
    写个入口文件,遍历*.js 然后 pm2.start()
    dany813
    dany813
    Feb 28, 2022
    13
    写个 node 入口脚本
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1479 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 06:04 · PVG 14:04 · LAX 22:04 · JFK 01:04
    ♥ Do have faith in what you're doing.