Node.js 开发,windows 还是 linux?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12581416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js development, windows or linux?
提问by Gabriel Smoljár
I'm interested in web development on the Node.js platform. My host OS is Windows 7. What would be the preferd way to set up a development environment. Run it directly on the host or in a linux based virtual machine? What are the pros and cons between these two methods?
我对 Node.js 平台上的 Web 开发感兴趣。我的主机操作系统是 Windows 7。设置开发环境的首选方式是什么。直接在主机上运行还是在基于 linux 的虚拟机中运行?这两种方法的优缺点是什么?
If I go with a VM, can I still run the text editor and web browser in Windows (for performance reasons)?
如果我使用虚拟机,我是否仍然可以在 Windows 中运行文本编辑器和 Web 浏览器(出于性能原因)?
采纳答案by MarcWan
We have a system via which we just use a config file, which handles all our problems like path differences ("c:\blarg"
vs "~user/blarg"
) and, as a bonus, lets us control differences between debug and production environments.
我们有一个系统,通过它我们只使用一个配置文件,它处理我们所有的问题,比如路径差异("c:\blarg"
vs "~user/blarg"
),作为奖励,我们可以控制调试和生产环境之间的差异。
Node.js is cross platform, so we totally have developers working on all sorts of computers, and it's no problem at all.
Node.js 是跨平台的,所以我们完全有开发人员在各种计算机上工作,这完全没有问题。
This is an example config file I use on a file storage project:
这是我在文件存储项目中使用的示例配置文件:
/**
* All of these are mandatory except for log_level (which defaults to "info", 1)
* and log_echo_to_console (which defaults to false)
*/
exports.config = {
log_level: 0,
log_file: "/path/to/send.log",
request_log_file: "/path/to/send_requests.log",
log_echo_to_console: true,
port_number: 8088,
no_notification_emails: true,
image_url_base: "http://s3.amazonaws.com/", // MAKE SURE THIS ENDS IN "/"
tmp_file_folder:"/tmp/",
s3_info: {
key: 'xxxxxx',
secret: 'yyyyy',
file_bucket: 'sendtransfer/',
},
backend_info: {
db_info: {
server: "localhost",
user: "db_user",
password: "secret",
database: "SendRemote",
pooled_connections: 125,
idle_timeout_millis: 30000
},
memcache_info: {
host: "127.0.0.1",
port: "31111",
pooled_connections: 200,
timeout: 20000
}
},
debug_server: true
};
For Windows machines, just change the paths. It's all good!
对于 Windows 机器,只需更改路径。都很好!
Then in code, you can just type:
然后在代码中,您只需键入:
var local = require('local.config.js');
fs.writeFile(local.config.log_file);
// etc
Embrace multiculturalism!!!
拥抱多元文化!!!
回答by supernova
I am also on Windows 7 and use Virtualbox with a Linux ( debian ) guest, i would recommand it because I for myself am faster doing some stuff in the commandline then clicking arround in Windows.
我也在 Windows 7 上使用 Virtualbox 和 Linux ( debian ) 来宾,我会推荐它,因为我自己更快地在命令行中做一些事情,然后在 Windows 中单击周围。
Another nice feature is that if you put your VM on an USB stick you can take it with you and use it everywhere where a Virtualbox Host is installed, so you can take your whole development environment with you.
另一个不错的功能是,如果您将 VM 放在 U 盘上,您可以随身携带它并在安装了 Virtualbox Host 的任何地方使用它,因此您可以随身携带整个开发环境。
It's no problem at all to use your favourite text editor or browser in Windows, just install samba and mount your home directory into Windows. Same goes for your browser since the VM is just another machine in your LAN, instead of pointing your browser to localhost point it to the VMs Ip and you are fine.
在 Windows 中使用您喜欢的文本编辑器或浏览器完全没有问题,只需安装 samba 并将您的主目录挂载到 Windows 中即可。您的浏览器也是如此,因为 VM 只是您 LAN 中的另一台机器,而不是将您的浏览器指向 localhost,将其指向 VM Ip 就可以了。
Obvious con here is if you don't have any experience with Linux yet you should probably stick to windows because it will take you some time to get into it.
这里明显的缺点是,如果您没有任何 Linux 经验,但您可能应该坚持使用 Windows,因为这需要您花一些时间才能上手。
回答by Robert Peters
I really enjoy coding node.js on windows using git bash: http://blog.nodester.com/post/19902515151/tips-for-windows-users
我真的很喜欢在 Windows 上使用 git bash 编写 node.js:http: //blog.nodester.com/post/19902515151/tips-for-windows-users
It's seems faster then and easier then running VirtualBox. Given that I still use Virtual Box for testing before going to production.
它似乎比运行 VirtualBox 更快更容易。鉴于我在投入生产之前仍然使用 Virtual Box 进行测试。
回答by sivi
just my two cents maybe even less:
只是我的两美分甚至更少:
I'll suggest you a third option: to double install windows/ubuntu setup (preferably ubuntudist which is most gui friendly) and research this option as well this way you would be more familiar with the linux/unix and even iOS which will even make you understand windows better and a better programmer. Sometimes the virtual box is too slow, while linux is very efficient with resources.
我会建议你第三个选项:双重安装 windows/ubuntu 设置(最好是对 gui 最友好的ubuntudist)并研究这个选项,这样你会更熟悉 linux/unix 甚至 iOS,它甚至会让你更好地理解windows,成为更好的程序员。有时候虚拟机太慢了,而linux在资源上非常高效。
If you have the ability to install a virtual machine,you can also give a go to installing a linux distributionand get yourself familiar with this language/system of OS which a lot of the web is structured upon
如果您有能力安装虚拟机,您还可以尝试安装linux 发行版,并熟悉这种语言/操作系统的系统,许多网络都基于该语言/系统构建
回答by airtonix
Eh from experience, use LinuxDocker.
Eh 从经验,使用 Linux码头工人。
editUse Docker. bake in your dependencies, mount your project at run time, pin to a particular version of LTS node only. I'd take a 2gb docker image over un-runnable project leading to days lost being forced to upgrade to new packages. - 2018/04/10
编辑使用 Docker。烘焙您的依赖项,在运行时挂载您的项目,仅固定到特定版本的 LTS 节点。我会在无法运行的项目上使用 2gb docker 映像,从而导致被迫升级到新软件包的时间损失了几天。- 2018/04/10
But from someone whose spent the last 8 years developing in a linux based environment, and having spent the last 6 months developing software using nodejs in a windows dot net environment, here are my discoveries, shocking or otherwise...
但是,从过去 8 年在基于 linux 的环境中进行开发,并在过去 6 个月内在 windows dot net 环境中使用 nodejs 开发软件的人那里,这是我的发现,令人震惊或其他...
Problems on windows:
窗户问题:
can't effectively utilise dockerLatest version of the docker toolkit solves this as far as I'm concerned. ymmv.- most node modules require node_gyp, which on the surface doesn't seem problematic (since gyp is supposed to be cross platform compiler), except when you delve into what it takes to get this working on windows: nothing short of installing visual studio will work. This sucks for me due to several reasons:
- I'm normally on linux, so I never want to have to use visual studio.
- It's entirely the most ridiculous idea that compiling something on windows requires at minimum a 3GB installation of an IDE... not libs but an entirely monolithic piece of GUI software I'll never ever launch.
the windows equivalent of debians
build-essentials
is actually a disparate sprawling ill named collection of gui only installers scattered across the internet all requiring a specific installation sequence. This, compared tosudo apt-get install build-essentials
is overly time consuming and fraught with hidden gotchas.developing on windows will allow you the bad habit of mixed case path names, unless your team either has a strict policy that is followed/enforced this will be a slippery slope to problems later on.
while windows supports more than 256 characters in paths, important tooling through out does not. enter stage left: rimraf and robocopy... ugh.
the windows terminal sucks... so does the default shell: cmd.exe...
Powershell is far too verbose in it's syntax and not to my taste... Installing Cmder aleviates this somewhat, however the only way for Cmder to interface with cmd.exe is to basically copy keystrokes to a hidden windows terminal running cmd.exe. (lolwut). Cmder works a lot better with shells that a more modular (zsh, bash, etc).. update: I now use powershell with pshazz and scoop, which is actually pleasant to use.Having still improved the shell and terminal situation, nodejs for windows will still assume your environment variables are %OF% %THE% %WINDOWS% %VARIETY%... not the $UNIX $STYLE. So you'll basically be using bower and npm mostly from cmd.exe... more ugh.I dont' seem to be having this issue anymore since I've incorporated a mix ofcross-env
and commander or yargs.You'll also need to install python for windows, not a problem because choco exists and has you back there. update: have a look at boxstarter, will help automate your new machine setup with recipes (or you could actually graduate to using ansible or salt).
experienced python, ruby developers will tell you that old projects will need the version of their engine silo'd for when you need to revisit them (upgrading to newer versions is mostly not expedient or practical, read: rabbit holes), so you'll want something like rvm and virtualenv...
nvm (which only works on unix systems linux and macosx) because it's a collection of bash scripts. I recommend using ZSH as your shell along with Zgen and
Tarrasch/zsh-autoenv
plugin.- nodeenv, which is more likely... a python program that integrates with virtualenv. Some people like this. I have no problem with it, but our team uses nvm.
however, you're better off with nvm-windows because "reasons".scratch that, usenodist
on windows... bar far the better choice, you won't need to worry about some kind of autoenv since nodist by design handles this.
无法有效利用 docker就我而言,最新版本的 docker 工具包解决了这个问题。嗯。- 大多数节点模块需要 node_gyp,从表面上看似乎没有问题(因为 gyp 应该是跨平台编译器),除非你深入研究在 Windows 上运行它需要什么:安装visual studio 就可以了. 由于以下几个原因,这对我来说很糟糕:
- 我通常使用 linux,所以我不想使用 Visual Studio。
- 在 Windows 上编译一些东西需要至少 3GB 的 IDE 安装,这完全是最荒谬的想法……不是库,而是一个我永远不会启动的完全单一的 GUI 软件。
相当于 debians 的 windows
build-essentials
实际上是分散在互联网上的一组不同的杂乱命名的 gui 安装程序,所有安装程序都需要特定的安装顺序。相比之下,这sudo apt-get install build-essentials
过于耗时且充满了隐藏的陷阱。在 Windows 上开发将使您养成混合大小写路径名称的坏习惯,除非您的团队遵循/执行严格的政策,否则这将是以后出现问题的滑坡。
虽然 Windows 支持路径中超过 256 个字符,但重要的工具不支持。进入舞台左侧:rimraf 和 robocopy ......呃。
Windows 终端很糟糕......默认外壳也是如此:cmd.exe ...
Powershell 的语法过于冗长,不符合我的口味......安装 Cmder 可以稍微缓解这种情况,但是 Cmder 与 cmd.exe 交互的唯一方法是基本上将击键复制到运行 cmd.exe 的隐藏 Windows 终端。(笑)。Cmder 与更模块化的 shell(zsh、bash 等)一起工作得更好。. 更新:我现在使用带有 pshazz 和 scoop 的 powershell,这实际上使用起来很愉快。仍然改进了 shell 和终端情况,windows 的 nodejs 仍然会假设你的环境变量是 %OF% %THE% %WINDOWS% %VARIETY%...而不是 $UNIX $STYLE。所以你基本上会使用 bower 和 npm 主要来自 cmd.exe ......更多呃。我似乎不再有这个问题,因为我已经合并了cross-env
指挥官或 yargs。您还需要为 Windows 安装 python,这不是问题,因为 choco 存在并且让您回到那里。更新:看看 boxstarter,它将帮助您使用配方自动化您的新机器设置(或者您实际上可以毕业使用 ansible 或 salt)。
经验丰富的 python,ruby 开发人员会告诉你,当你需要重新访问它们时,旧项目将需要他们的引擎筒仓版本(升级到新版本通常不是权宜之计或实用,请阅读:兔子洞),所以你会想要 rvm 和 virtualenv 之类的东西...
nvm(仅适用于 unix 系统 linux 和 macosx),因为它是 bash 脚本的集合。我建议使用 ZSH 作为 shell 以及 Zgen 和
Tarrasch/zsh-autoenv
插件。- nodeenv,这更有可能......一个与virtualenv集成的python程序。有些人喜欢这样。我没有问题,但我们的团队使用 nvm。
但是,由于“原因”,您最好使用 nvm-windows。从头开始,nodist
在 Windows 上使用... bar 是更好的选择,您无需担心某种 autoenv,因为 nodist 按设计处理此问题。
Installing on Windows:
在 Windows 上安装:
- install chocolatey
choco install cmder nodejs python2
choco install python2
- install
http://scoop.sh
, then use it to install pshazz. - remove any versions of node manually installed globally.
install nvm-windowsinstall nodist.install visual-studio 2012 express, then never launch it if you treasure your cpu cycles.this may be overkill as microsoft have released an equivalent to build-essentials.- install windows 7/10 64bit sdk
- 安装巧克力
choco install cmder nodejs python2
choco install python2
- install
http://scoop.sh
,然后用它来安装 pshazz。 - 删除全局手动安装的任何版本的节点。
安装 nvm-windows安装 nodist。安装visual-studio 2012 express,如果你珍惜你的cpu周期,那就永远不要启动它。这可能有点矫枉过正,因为微软已经发布了一个相当于 build-essentials 的软件。- 安装 Windows 7/10 64 位 SDK
Problems on Linux:
Linux 上的问题:
tldr; use nvm. for more reasons other than the below.
tldr; 使用 nvm。出于以下原因以外的更多原因。
you'll have to set the global npm node_modules path to a user owned directory (I've started usingA non issue when using nvm.~/.local/share/npm
). Pleasantly, this is something I found the windows installation of nodejs got right (probably not intentionally).Ubuntu already has a binary calledalso a non issue when using nvm.node
, so#!/usr/bin/env node
will by default not run nodejs. luckily debian systems have a neat management tool for controlling what theenv
binary emits:update-alternatives
. ignore suggestions to use symlinks here, which will only cause problems later on in subtle ways.
您必须将全局 npm node_modules 路径设置为用户拥有的目录(我已经开始使用使用 nvm 时没有问题。~/.local/share/npm
)。令人愉快的是,这是我发现 nodejs 的 Windows 安装是正确的(可能不是故意的)。Ubuntu 已经有一个名为 的二进制文件使用 nvm 时也不是问题。node
,因此#!/usr/bin/env node
默认情况下不会运行 nodejs。幸运的是,debian 系统有一个简洁的管理工具来控制env
二进制文件发出的内容:update-alternatives
. 忽略此处使用符号链接的建议,这只会在以后以微妙的方式引起问题。
Installing on Linux :
在 Linux 上安装:
$ sudo apt-get install git-core git-flow build-essentials python-dev python- pip
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
$ npm config set prefix ~/.local/share/npm
$ nvm install stable
$ nvm alias default stable
references:
参考:
- https://groups.google.com/forum/?fromgroups#!msg/msysgit/9YIR6jlNB0Q/zHhPN3tejFkJ
- https://github.com/creationix/nvm
http://bliker.github.io/cmder/https://github.com/coreybutler/nvm-windows- https://github.com/Tarrasch/zsh-autoenv
- https://github.com/lukesampson/pshazz
- http://scoop.sh
- https://github.com/marcelklehr/nodist
- https://groups.google.com/forum/?fromgroups#!msg/msysgit/9YIR6jlNB0Q/zHhPN3tejFkJ
- https://github.com/creationix/nvm
http://bliker.github.io/cmder/https://github.com/coreybutler/nvm-windows- https://github.com/Tarrasch/zsh-autoenv
- https://github.com/lukesampson/pshazz
- http://scoop.sh
- https://github.com/marcelklehr/nodist