Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js development, windows or linux?

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)?

like image 766
Gabriel Smoljár Avatar asked Sep 25 '12 10:09

Gabriel Smoljár


People also ask

Which OS is best for node js development?

Windows is a perfectly fine system to both develop node applications as well as to deploy them. Microsoft partnered with Joyent to help them port the code and the Windows Azure cloud hosting environment supports Node. js now. All of the npm packages I have used have had not problems running on Windows.

Is Windows good for node JS?

node. js runs just fine on Windows, so why leave the well-known environment? Just a thought. Some environments run better on linux and vice versa.

Is it worth learning node JS in 2022?

Js Is Popular. Node js in 2022 looks like a massive trend that is going to evolve even more. It offers some undeniable benefits that make it the best choice for software developers.

Is Nodejs easier than Python?

js vs Python, Node. js is faster due to JavaScript, whereas Python is very slow compared to compiled languages. Node. js is suitable for cross-platform applications, whereas Python is majorly used for web and desktop applications.


2 Answers

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:

  • 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
like image 124
airtonix Avatar answered Oct 11 '22 07:10

airtonix


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

like image 45
MarcWan Avatar answered Oct 11 '22 07:10

MarcWan