How To Work With JSON In Node.js / JavaScript


String To JSON Object:

This is very much easier and straight forward as below:

var jsonString = "{\"key\":\"value\"}";
var jsonObj = JSON.parse(jsonString);

As you can see, we are using the built-in global JSON Object to parse a string which has JSON Data. Also, it might be good idea to use “.trim()” method on the string, if you think there might be some chance of extra space etc in the JSON string. Otherwise, it won’t get parsed and you will face an unexpected error.

Continue reading

Install NodeJs


Untuk install nodeJs silakan ikuti comment berikut ini :

1. sudo apt-get install python-software-properties
2. sudo apt-add-repository ppa:chris-lea/node.js
3. sudo apt-get update
4. sudo apt-get install nodejs

Setelah mengikuti langkah – langkah di atas, silakan ketik command node –version

maka akan nampak version nodejs anda di ubuntu