Node中的"process.env.USER"和"process.env.USERNAME"之间有什么区别? [英] What is the difference between `process.env.USER` and `process.env.USERNAME` in Node?

查看:310
本文介绍了Node中的"process.env.USER"和"process.env.USERNAME"之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我可以找到的关于process.env属性的最强大的文档: https://nodejs.org/api/process.html#process_process_env .

This is the most robust documentation I can find for the process.env property: https://nodejs.org/api/process.html#process_process_env.

它提到USER,但没有提到USERNAME.在我的机器上(Windows/Bash),当我打印process.env的内容时,看到的是USERNAME(我的Windows用户名),但没有看到USER.同样,echo $USERNAME显示我的名字,但echo $USER不返回任何内容.

It mentions USER, but not USERNAME. On my machine (Windows/Bash), when I print the contents of process.env, I see USERNAME (my windows username) but not USER. Similarly, echo $USERNAME shows my name but echo $USER returns nothing.

USERUSERNAME有什么区别?是操作系统吗?它们可以互换吗?

What is the difference between USER and USERNAME? Is it an operating system thing? Are they interchangeable?

推荐答案

process.env是流程的环境变量,由操作系统提供给进程.

process.env is the process's environment variables, which are supplied by the OS to the process.

此对象实际上可以包含几乎所有内容,具体取决于操作系统和启动它的进程,但是默认情况下,Windows将用户名存储在USERNAME中,而类Unix系统(Linux,macOS等)将其存储在USER.

This object can really contain just about anything, as specified the OS and the process that launches it, but by default Windows stores the username in USERNAME and Unix-like systems (Linux, macOS, etc.) store it in USER.

这篇关于Node中的"process.env.USER"和"process.env.USERNAME"之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆