Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md Update simple example README Apr 2, 2018
index-pre-v7.6.js Update build files and examples Jan 24, 2018
index.js Update build files and examples Jan 24, 2018
package.json Bump version to v1.2.1 Mar 16, 2018

README.md

Simple example project

Simple project demonstrating the use of dgraph-js, the official javascript client for Dgraph.

Running

Start Dgraph server

You will need to install Dgraph v0.9.4 or above and run it.

You can run the commands below to start a clean Dgraph server every time, for testing and exploration.

First, create two separate directories for dgraph zero and dgraph server.

mkdir -p dgraphdata/zero dgraphdata/data

Then start dgraph zero:

cd dgraphdata/zero
rm -r zw; dgraph zero
# If running Dgraph version <= 1.0.2, use the following command instead:
# rm -r zw; dgraph zero --port_offset -2000

Finally, start the dgraph server:

cd dgraphdata/data
rm -r p w; dgraph server --memory_mb=1024 --zero localhost:5080

For more configuration options, and other details, refer to docs.dgraph.io

Install dependencies

npm install

Run the sample code

For Node.js >= v7.6, run:

node index.js

For Node.js < v7.6 or if you don't want to use the async/await syntax, run:

node index-pre-v7.6.js

Your output should look something like this (uid values may be different):

Created person named "Alice" with uid = 0x7569

All created nodes (map from blank node names to uids):
blank-0: 0x7569
blank-1: 0x756a
blank-2: 0x756b
blank-3: 0x756c

Number of people named "Alice": 1
{ uid: '0x7569',
  name: 'Alice',
  age: 26,
  married: true,
  loc: { type: 'Point', coordinates: [ 1.1, 2 ] },
  dob: '1980-02-01T17:30:00Z',
  friend: [ { name: 'Bob', age: 24 }, { name: 'Charlie', age: 29 } ],
  school: [ { name: 'Crown Public School' } ] }

DONE!

You can explore the source code in the index.js and index-pre-v7.6.js files.