In this short tutorial I will try to show you how to install Node.js and Elastos Node.js demo application. The result of our effort should be two instances of application as two different users who can talk to each other, adding friends etc.

Node.js demo application is clone of the Carrier Native SDK shell demo app. The shell demo app is a command line app so you can interact with it through Terminal.

Installing Homebrew and Node.js

The simplest way how to install Node.js on MacOS is with Homebrew. Homebrew is a package management system that simplifies the installation of software so if you do not have it, open Terminal and run this command:

$ /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It is good to make sure that Homebrew is up to date:

$ brew update

With working Homebrew is installing of Node.js really straightforward, just run this command and wait:

$ brew install node

Check the version of Node.js:

$ node -version

Preparing Demo application

If you do not have GIT installed on your Mac, Homebrew will help:

$ brew install git

Ok, now have everything needed for running Demo application. But you still need that demo aplication, right? So go to your favorite working directory and clone Elastos.NET.Carrier.Nodejs.SDK repository:

Now you can install Elastos Carrier Node.js Addon:

$ cd Elastos.NET.Carrier.Nodejs.SDK/example/demo/

$ npm install

For testing purposes it is better to have two instances of Demo application. Because application saves data to .data folder, the easier way how to create two instances is simply by copying demo folder:

$ cp -r demo demo2

For clarity I recommend to rename demo folder to demo1:

$ mv demo demo1

So the folder structure looks like this:

$ ls -la

total 8

drwxr-xr-x 5 tomsej 372714609 160 Apr 15 12:08 .

drwxr-xr-x 18 tomsej 372714609 576 Apr 15 11:36 ..

-rw-r — r — 1 tomsej 372714609 329 Apr 15 10:57 README.md

drwxr-xr-x 8 tomsej 372714609 256 Apr 15 11:36 demo1

drwxr-xr-x 8 tomsej 372714609 256 Apr 15 11:36 demo2

Running Demo application

Finally we can run Elastos application. As I mentioned for testing purposes I am going to create two instances of Demo application (demo1 and demo2).

Running demo1:

$ cd Elastos.NET.Carrier.Nodejs.SDK/example/demo1/

$ node demo.js

elacarrier-5.0.1

2018–04–15 11:07:16 — INFO : Carrier: Carrier node created.

(node:60556) Warning: N-API is an experimental feature and could change at any time. Friends list from carrier network:

ID Connection Label

— — — — — — — — — — — — — — — -

— — — — — — — —

Total 0 friends.

Connected to carrier network.

Running demo2 (in new Terminal tab or window):

$ cd Elastos.NET.Carrier.Nodejs.SDK/example/demo2/

$ node demo.js

elacarrier-5.0.1

2018–04–15 11:08:22 — INFO : Carrier: Carrier node created.

(node:60937) Warning: N-API is an experimental feature and could change at any time. Friends list from carrier network:

ID Connection Label

— — — — — — — — — — — — — — — -

— — — — — — — —

Total 0 friends.

Connected to carrier network.

Playing with Demo application

Now you should have two instances of Demo application up and running.

To list all available commands just write:

Command:$ help

Available commands list:

help [cmd]

address

nodeid

userid

me [set] [name | description | gender | phone | email | region] [value]

nospam [ value ]

presence [ none | away | busy ]

fadd address hello

faccept userid

fremove userid

friends

friend userid

label userid name

msg userid message

invite userid data

ireply userid [confirm message | refuse reason]

exit

Ok, now it is time to make some friends. Maybe it is kind of selfish because you are going to add yourself as your only friend. But you can still chat with each other well.

First you need to know your address so in demo1 write:

Command:$ address

MTxWYWcwKdwni6C2Sz9BT26A4szf6B5e3En7WdicV27WT3cC9hvE

With this address you can send friend request from demo2 app:

Command:$ fadd MTxWYWcwKdwni6C2Sz9BT26A4szf6B5e3En7WdicV27WT3cC9hvE hello

Request to add a new friend succeess.

New friend added. The friend information:

ID: AK2qGF81zQ2uFn921SGxSxXCj1H9ZdPooBDGHYrh6Eg6

Name:

Description:

Gender:

Phone:

Email:

Region:

Presence: none

Connection: offline

After few seconds you should see similar command as callback in demo1 app:

Reply use following commands:

faccept D9YQv36TVBjVHJQnEHk8sM9EYYEZSnQGjqGCb7fEJeYn

You can simply copy this command to make your first friend:

Command:$ faccept D9YQv36TVBjVHJQnEHk8sM9EYYEZSnQGjqGCb7fEJeYn

Accept friend request success.

To list all your friends write:

Command:$ friends

Friends list from carrier network:

ID Connection Label

— — — — — — — — — — — — — — — -

D9YQv36TVBjVHJQnEHk8sM9EYYEZSnQGjqGCb7fEJeYn online

— — — — — — — —

Total 1 friends.

Finally you can say Hi to yourself (of course you need to change has in the middle):

Command:$ msg D9YQv36TVBjVHJQnEHk8sM9EYYEZSnQGjqGCb7fEJeYn Hi

Ok that is all for now, hope you liked it. There is of course more functionality in this demo app but you will find it yourself.

In next tutorial I will try to create some simple API with Elastos, so stay tuned.