37

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?

If I go with a VM, can I still run the text editor and web browser in Windows (for performance reasons)?

Gabriel Smoljár
  • 1,175
  • 2
  • 13
  • 32
  • 6
    node.js runs just fine on Windows, so why leave the well-known environment? – Joachim Sauer Sep 25 '12 at 10:56
  • 4
    Just a thought. Some environments run better on linux and vice versa. And some platforms are so complex that you may want to virtualize them. I take it that there's nothing to gain form virtualizing a Node.js dev environment for small projects? – Gabriel Smoljár Sep 25 '12 at 12:55
  • Running node.js for production might work better on Linux (I honestly don't know, but it's a reasonable guess, since it was initially developed on a Unix-y platform). But for *development* work the "performance" of the user on the desktop is usually *much* more important than the raw performance of the server environment. – Joachim Sauer Sep 25 '12 at 14:27
  • Nothing touched by a lot of JS devs will work 'best' on a single platform for long. – Erik Reppen Jun 15 '13 at 23:20
  • Linux, NodeJS and NPM developer hates Windows and in fact doesn't use it. He's not fixing the bugs in this platform. – Bruno Finger Mar 16 '16 at 10:27
  • @GabrielSmoljár There's always something to be gained from virtualising or dockerising your project. Unless of course you never work in teams and never revisit old projects (or even deploy them). Reliably reproducible is something you really want to strive for. – airtonix Nov 26 '16 at 16:59
  • This is just my opinion but the Node community seems to be overrun with Apple fanboys who never test on Linux or Windows. Because of this I've found that application development on any platform other than OSx is a pain in the butt. – Shawn Whinnery Dec 18 '17 at 20:10

5 Answers5

41

Eh from experience, use Linux Docker.

edit Use 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

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...

Problems on windows:

  • can't effectively utilise docker Latest 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 to sudo 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 of cross-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, use nodist on windows... bar far the better choice, you won't need to worry about some kind of autoenv since nodist by design handles this.

Installing on Windows:

  1. install chocolatey
  2. choco install cmder nodejs python2 choco install python2
  3. install http://scoop.sh, then use it to install pshazz.
  4. remove any versions of node manually installed globally.
  5. install nvm-windows install nodist.
  6. 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.
  7. install windows 7/10 64bit sdk

Problems on Linux:

tldr; use nvm. for more reasons other than the below.

  • you'll have to set the global npm node_modules path to a user owned directory (I've started using ~/.local/share/npm). Pleasantly, this is something I found the windows installation of nodejs got right (probably not intentionally). A non issue when using nvm.
  • Ubuntu already has a binary called node, so #!/usr/bin/env node will by default not run nodejs. luckily debian systems have a neat management tool for controlling what the env binary emits: update-alternatives. ignore suggestions to use symlinks here, which will only cause problems later on in subtle ways. also a non issue when using nvm.

Installing on 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:

airtonix
  • 3,859
  • 1
  • 30
  • 32
  • 5
    I agree, use linux if you want less hassle with NodeJS and all its packages. – J86 Jan 29 '15 at 14:21
  • We never stopped experiencing problems with node on windows. Have since moved to using docker to normalise our development environment. Solid experience. never experience problems since. we are also 3rd party dependancy and offline resistant now. – airtonix Apr 10 '18 at 05:40
21

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.

Node.js is cross platform, so we totally have developers working on all sorts of computers, and it's no problem at all.

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!

Then in code, you can just type:

var local = require('local.config.js');
fs.writeFile(local.config.log_file);
// etc

Embrace multiculturalism!!!

MarcWan
  • 2,873
  • 3
  • 25
  • 40
  • 2
    Are all 3rd party modules also cross platform? Like, mongooid, express and restify? – Gabriel Smoljár Sep 25 '12 at 15:03
  • 1
    I've literally never had a single problem so far. We've used a bunch of different modules, and no problems. Theoretically, node modules will configure themselves for the various platforms when you install them. I suppose there COULD be problems eventually, but we haven't seen any thus far. – MarcWan Sep 26 '12 at 01:53
  • Try and installing topojson on Windows! Such a damn hassle that I had to install Ubuntu into a VM! :( – J86 Jan 29 '15 at 14:20
6

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.

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.

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.

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.

supernova
  • 3,606
  • 2
  • 19
  • 34
2

just my two cents maybe even less:

I'll suggest you a third option: to double install windows/ubuntu setup (preferably ubuntu dist 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.

If you have the ability to install a virtual machine,you can also give a go to installing a linux distribution and get yourself familiar with this language/system of OS which a lot of the web is structured upon

sivi
  • 9,048
  • 2
  • 43
  • 47
0

I really enjoy coding node.js on windows using git bash: 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.

Robert Peters
  • 2,744
  • 1
  • 15
  • 9