This example shows how to install biicode and code a node.js redis client. You don’t need to have installed redis, biicode will download for you, it is already in biicode!
First download and install biicode
Then, download and install on your system the appropriate version of Node.js .
First, create a project:
~$ bii init myproject
Then we can use the convenience new
command to create some folders and a “Hello World” Node.js main file. Of course, you can do it manually too.
~$ cd myproject
~/myproject$ bii new myuser/myblock --hello=node
myuser
, there’s no need to register an account to use biicode, only
to upload and share contents. You can use other name too.
If you have already registered you might want to replace myuser
with your real biicode username.This should be the resulting layout:
+-- myproject
| +-- bii
| +-- blocks
| | +-- myuser
| | | +-- myblock
| | | | +-- main.js
| +-- deps
Lets check that everything is fine by running the hello world aplication.
~/myproject/$ cd blocks
~/myproject/blocks$ noderunner
myuser/myblock/main.js
Copy the following code containing a simple redis client into the main.js file:
main.js
var redis = require("mranney/node_redis");
client = redis.createClient();
client.set("str key","str val", redis.print);
client.quit(function (err, res) {
console.log("Exiting from quit command.");
});
~/myproject$ bii find
Run a redis server. If you need to install redis, you can download it from redis.io.
~/myproject$ redis server
Now, execute your script main.js.
~/myproject/$ cd blocks
~/myproject/blocks$ noderunner myuser/myblock/main.js
Reply: OK
Exiting from quit command.
That’s it, if you see that output redis was downloaded and configured in your project!
You can check the deps
folder, the redis code is there.
Didn’t work? No problem, read or contact us in the biicode forum
Any suggestion or feedback? Write us! It is very welcomed :)