# Setting up Development Environment

## Install Node.js

Install Node.js by your favorite method, or use Node Version Manager by following directions at https://github.com/creationix/nvm

```bash
nvm install v4
```

## Fork and Download Repositories

To develop gewelcore-node:

```bash
cd ~
git clone git@github.com:<yourusername>/gewelcore-node.git
git clone git@github.com:<yourusername>/gewelcore-lib.git
```

To develop gewel or to compile from source:

```bash
git clone git@github.com:<yourusername>/gewel.git
git fetch origin <branchname>:<branchname>
git checkout <branchname>
```
**Note**: See gewel documentation for building gewel on your platform.


## Install Development Dependencies

For Ubuntu:
```bash
sudo apt-get install libzmq3-dev
sudo apt-get install build-essential
```
**Note**: Make sure that libzmq-dev is not installed, it should be removed when installing libzmq3-dev.


For Mac OS X:
```bash
brew install zeromq
```

## Install and Symlink

```bash
cd gewelcore-lib
npm install
cd ../gewelcore-node
npm install
```
**Note**: If you get a message about not being able to download gewelcore distribution, you'll need to compile geweld from source, and setup your configuration to use that version.


We now will setup symlinks in `gewelcore-node` *(repeat this for any other modules you're planning on developing)*:
```bash
cd node_modules
rm -rf gewelcore-lib
ln -s ~/gewelcore-lib
rm -rf geweld-rpc
ln -s ~/geweld-rpc
```

And if you're compiling or developing gewel:
```bash
cd ../bin
ln -sf ~/gewel/src/geweld
```

## Run Tests

If you do not already have mocha installed:
```bash
npm install mocha -g
```

To run all test suites:
```bash
cd gewelcore-node
npm run regtest
npm run test
```

To run a specific unit test in watch mode:
```bash
mocha -w -R spec test/services/geweld.unit.js
```

To run a specific regtest:
```bash
mocha -R spec regtest/geweld.js
```

## Running a Development Node

To test running the node, you can setup a configuration that will specify development versions of all of the services:

```bash
cd ~
mkdir devnode
cd devnode
mkdir node_modules
touch gewelcore-node.json
touch package.json
```

Edit `gewelcore-node.json` with something similar to:
```json
{
  "network": "livenet",
  "port": 3001,
  "services": [
    "geweld",
    "web",
    "insight-api",
    "insight-ui",
    "<additional_service>"
  ],
  "servicesConfig": {
    "geweld": {
      "spawn": {
        "datadir": "/home/<youruser>/.gewelcore",
        "exec": "/home/<youruser>/gewel/src/geweld"
      }
    }
  }
}
```

**Note**: To install services [insight-api](https://github.com/gewelio/insight-api) and [insight-ui](https://github.com/gewelio/insight-ui) you'll need to clone the repositories locally.

Setup symlinks for all of the services and dependencies:

```bash
cd node_modules
ln -s ~/gewelcore-lib
ln -s ~/gewelcore-node
ln -s ~/insight-api
ln -s ~/insight-ui
```

Make sure that the `<datadir>/gewel.conf` has the necessary settings, for example:
```
server=1
whitelist=127.0.0.1
txindex=1
addressindex=1
timestampindex=1
spentindex=1
zmqpubrawtx=tcp://127.0.0.1:28332
zmqpubhashblock=tcp://127.0.0.1:28332
rpcallowip=127.0.0.1
rpcuser=gewel
rpcpassword=local321
```

From within the `devnode` directory with the configuration file, start the node:
```bash
../gewelcore-node/bin/gewelcore-node start
```