CiviCRM from node.js helps you make friends

Published
2012-10-27 07:28
Written by
xavier - member of the CiviCRM community - view blog guidelines

Hi,

Node.js allows to run javascript on the server and is great for real time applications when you want to have lots of users and connections at the same time

I wrote a node module to easily connect to a civicrm server from that node.js. I found a cool module that makes it easy to generate names, addresses, phone number and emails and hacked a quick example of how civi can be used from node.js.

Without further intro:

 

Imaginary friends on CiviCRM

You have installed civicrm, but realised you don't have friends or contacts? Fed up of having activities with the same 102 contacts that ship by default with civi?

civi-charlatan is going to fill your social life with lots of interesting sounding contacts from all around the world. You will even have their emails, addresses and phones!

It's like buying followers on twitter or "like" on facebook, but even better, it's free.

That or you want more realistic development enviroments containing a few 1000th contacts. This tool generates contacts (with address, email and phone) and add them to your civicrm (using REST API).

Testing with node on the same laptop as my civi, generated 2000 individuals (+their employees) in less than 3 min. Hopefully, it will help testing and identifying sql queries in civicrm that needs some improvements.

I plan to use it as well for our next trainings to provide a more complete install.

It's using the wonderful charlatan to generate the names/emails/phones

Installation

you need to have a working node with npm

download civi-charlatan and unzip it or go the git way

$git clone https://github.com/tttp/civi-charlatan.git

and install its dependencies

$cd civi-charlatan; npm install

Configuration

You need to set up your civicrm to accept REST. The usual setup:

  • be sure you have an site key in your site civicrm.settings.php (it should be there already)
  • you need a user (that is going to be the creator of the contacts) that have a api_key connect to your civicrm database 
mysql> update civicrm_contact set api_key="aaaa" where id=1; or whatever user id you have

If your civicrm version is < 4.2.5, you need to apply this patch http://issues.civicrm.org/jira/browse/CRM-11169

you then need to copy (or edit) the config file config/example.json and put the url of your site, the api key and (site) key.

Usage

$node contact.js example 42

will create 42 contacts in the site defined into config/example.json I used the german, uk, us and nl locale (randomly) to have fields with chars outside of a-z and see if unicode is with us all the way. You will have names with quotes too (o' ...)

ex:

To make it easier to clean your db if needed, the source of these contacts is "imaginary friend".

If there is a need for it, I could add a web interface to make it easier to add contacts in you test enviroment without having to install node, but as most are probably not on a publicly accessible IP, not sure that'd be super useful.

For those developping on civi, I would suggest you to use it to have "production like" databases. It would be easy to improve civi charlatan so it creates activities or participants or contributions... and would hopefully help the development.

 

Filed under

Comments

Very cool!

One thing that I'd love to see added to this is the ability to generate email addresses that would go to me.  Gmail, for example, send any email that looks like username+something@gmail.com to username@gmail.com (where 'something' can be pertty much anything legal in email addresses, like a numberical index or an md5 hash).  This way I could generate thousands of users, create some groups, and test emails to those groups and have the emails sent to me.  I know I can also define('CIVICRM_MAIL_LOG', 1) but sometimes actually receiving the email is better for testing.

Thanks for a great tool!