What exactly does “/usr/bin/env node” do at the beginning of node files?

前端 未结 3 2015
南方客
南方客 2020-11-27 09:35

I had seen this line #!/usr/bin/env node at the beginning of some examples in nodejs and I had googled without finding any topic that could answer

3条回答
  •  执笔经年
    2020-11-27 10:27

    Short answer: It is the path to the interpreter.

    EDIT (Long Answer): The reason there is no slash before "node" is because you can not always guarantee the reliability of #!/bin/ . The "/env" bit makes the program more cross-platform by running the script in a modified environment and more reliably being able to find the interpreter program.

    You do not necessarily need it, but it is good to use to ensure portability (and professionalism)

提交回复
热议问题