Node-gyp on Windows with Visual C++ 2013

A common thing to do after installing Node.js on Windows is setting up node-gyp's compiler settings.
Node-gyp is needed for compiling native modules.

In my pc & laptop, I use Visual C++ 2013 compiler, so I need to do the following steps:

  • Set compiler version
npm config set msvs_version 2013 --global 
  • Update MSBuild Toolset settings of node-gyp.
    To do this I need to edit common.gypi file, normally found inside C:\Users\{username}\.node-gyp directory.
    You can refer to gimelfarb's comment here.
{
  ...
  'target_defaults': {
     ...
     'configurations': {
        ...
        'Release': {
          'conditions': [
            ['target_arch=="x64"', {
              'msvs_configuration_platform': 'x64',
              'msbuild_toolset': 'v120_xp'            <--- THIS LINE!
            }],
        }
     }
  }
}