In a previous post I have explained how to use Couchbase and Node.js on OS X. Since it is quite different on Windows here another article about it.
Install Couchbase Server 2.0
If you have not installed Couchbase Server already, do the following :
- Download Couchbase Server from here
- Run the installer
- Configure the database at http://localhost:8091 (if you have issue take a look to this article)
These steps are documented in the Couchbase Server Manual.
Install latest version of node
It is quite easy to install Node.js using the Windows installer provided at http://nodejs.org.
Once you have installed node, you can test is using the command line interface:
1 2 3
Node is installed. So far so good !
Couchnode, the Couchbase Client Library for Node.js, is a native module. The tool used to install native modules is
node-gyp. So to install couchnode you need to install :
- Visual Studio to have access to a C/C++ compiler
The node-gyp module is easy to install and you can install it using npm using the following command:
The -g parameter indicates that this module will be installed globally and added to your
GYP uses Python to generate the project, so you need to install it on your environment. I have installed Python 2.7.3 using the Windows installer.
Install Visual Studio
Finally you need a C/C++ compiler, the best way to get it is to install Visual Studio. As you probably know I am not a Windows expert and I do not know a lot about Microsoft development tools. I have downloaded Visual Studio Express the free development tools from here; it was sufficient.
Install Libcouchbase for Windows
Couchnode uses libcouchbase the C client library, so before running the npm install for Couchbase, you need to install libcouchbase itself.
You can download it from Couchbase site. The Windows versions are located in the left menu of the page. Download the zip file, that matches your environment. I have downloaded the “Windows, 64-bit MSVC 10”.
Node-gyp will look for all the dependencies (DLL, library headers) into
c:\couchbase directory, so you need to unzip the file in this folder. This location comes from the binding.gyp file of the couchnode project.
Install and Test Couchnode itself!
Let’s check what we have done so far; we have installed:
- Visual Studio
We are now ready to install and use couchnode itself. For this we can create a new node project.
1 2 3
The install command will:
- Create a node_modules folder and put couchbase client library in it
- When installing/building couchnode on Windows I had the following warning :
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(1138,5): warning MSB8012: TargetExt(.dll) does not match the Linker’s Output File property value (.node). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile). [C:\Users\tgrall\node\node_modules\couchbase\build\couchbase_impl.vcxproj]
This is only a warning and as far as I know, it is not a blocker. At the end of the log you should see:
1 2 3
You have successfully installed couchnode.
Let’s now write a small test. Create a
test.js file with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Run this with the command:
You should see the following text in your console :
In this article you have learned how to:
- Install Couchbase
- Install Node
- Install and configure node-gyp
- Install and use Couchbase and Node
all this on Windows 7.