<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>blog.gvm-it.eu</title><generator>Tumblr (3.0; @klovadis)</generator><link>http://blog.gvm-it.eu/</link><item><title>Introduction to the node.js EventEmitter</title><description>&lt;p&gt;When you start learning &lt;a href="http://www.nodejs.org/" target="_blank"&gt;node.js&lt;/a&gt; you soon stumble upon something called &lt;a href="http://nodejs.org/api/events.html" target="_blank"&gt;EventEmitter&lt;/a&gt;. The following post covers how the built-in &lt;a href="http://nodejs.org/api/events.html" target="_blank"&gt;EventEmitter&lt;/a&gt; works,  how you can use and why it is so useful.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2&gt;EventEmitter basics&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;There is no magic.&lt;/strong&gt; The &lt;em&gt;EventEmitter&lt;/em&gt; is pure JavaScript and the code of it can be found &lt;a href="https://github.com/joyent/node/blob/master/lib/events.js" target="_blank"&gt;here on GitHub&lt;/a&gt;. The following holds true for the &lt;em&gt;base EventEmitter&lt;/em&gt; class:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Typically the &lt;em&gt;EventEmitter&lt;/em&gt; class is included in a node module like this (&lt;em&gt;&amp;#8220;events&amp;#8221;&lt;/em&gt; is a node.js core module that has only one export, the &lt;em&gt;EventEmitter&lt;/em&gt;):
&lt;pre&gt;var EventEmitter = require("events").EventEmitter;&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;To create a simple EventEmitter instance, just instantiate a &lt;em&gt;new EventEmitter&lt;/em&gt;:
&lt;pre&gt;var myEventEmitter = new EventEmitter();&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;This is a common pattern that is used to inherit from the EventEmitter class; If you create an instance of &lt;em&gt;myClass&lt;/em&gt; it will have &lt;em&gt;EventEmitter&lt;/em&gt; functionality:
&lt;pre&gt;function myClass() { /* constructor */ }
myClass.prototype = new EventEmitter();&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;The &lt;em&gt;EventEmitter&lt;/em&gt; allows you to hook &lt;strong&gt;event listeners&lt;/strong&gt; onto the emitter that can listen for any arbitrary event using the following syntax:
&lt;pre&gt;myEventEmitter.on("event_name", fnListener);&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Event listeners are functions that are called once a specific event is &lt;em&gt;emitted&lt;/em&gt;. You can always emit any event like this:
&lt;pre&gt;myEventEmitter.emit("event_name", "arg1", "arg2");&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;When you &lt;em&gt;.emit()&lt;/em&gt; an event, any arguments that you pass after the &lt;em&gt;event_name&lt;/em&gt; will be passed to the attached event listeners.&lt;/li&gt;

&lt;li&gt;Also, when you have multiple event listeners attached to an event, &lt;em&gt;all&lt;/em&gt; of those event listeners will be called in the order that they were attached to it.&lt;/li&gt;

&lt;li&gt;Event names are completely arbitrary; If you create your own &lt;em&gt;EventEmitter&lt;/em&gt;, &lt;strong&gt;you&lt;/strong&gt; decide which events your &lt;em&gt;EventEmitter&lt;/em&gt; emits. If you don&amp;#8217;t emit your events, the listeners will never be fired.&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;Special event: error&lt;/h2&gt;

&lt;p&gt;There is one exception to the behaviour of events which is not found in the official documentation: When you &lt;em&gt;.emit()&lt;/em&gt; an &lt;em&gt;&amp;#8220;error&amp;#8221; event&lt;/em&gt; and you don&amp;#8217;t have any event listeners attached to it, an &lt;a href="http://nodejs.org/api/process.html#process_event_uncaughtexception" target="_blank"&gt;uncaughtException&lt;/a&gt; event is raised.&lt;/p&gt;

&lt;p&gt;This means that your &lt;a href="http://nodejs.org/api/process.html" target="_blank"&gt;node.js process&lt;/a&gt; - it itself is based on the &lt;em&gt;EventEmitter&lt;/em&gt; - will emit an event called &lt;em&gt;&amp;#8220;uncaughtException&amp;#8221;&lt;/em&gt;. This in turn will, if you don&amp;#8217;t have a listener for it, make your node process exit.&lt;/p&gt;

&lt;p&gt;Note that if you &lt;em&gt;throw&lt;/em&gt; an error that is not caught using &lt;em&gt;try .. catch&lt;/em&gt;, this will also raise an &lt;em&gt;&amp;#8220;uncaughtException&amp;#8221;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The take-away message is that &lt;strong&gt;if you raise &lt;em&gt;&amp;#8220;error&amp;#8221;&lt;/em&gt; events, be sure to listen 
for them&lt;/strong&gt; or be aware that they will crash your program.&lt;/p&gt;

&lt;h2&gt;Further functionality&lt;/h2&gt;

&lt;p&gt;The above explains the basic, most important, basic functionality. But of course, there does exist further functionality that can be of use:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Listen exactly one time to an event, then remove the listener:
&lt;pre&gt;myEventEmitter.once("event_name", fnListener);&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Remove one specific listener from an event:
&lt;pre&gt;myEventEmitter.removeListener("event_name", fnListener);&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Remove all listeners from an event
&lt;pre&gt;myEventEmitter.removeAllListeners("event_name")&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Retrieve all listener functions that are listening to an event, as an array:
&lt;pre&gt;var arListeners = myEventEmitter.listeners("event_name");&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;A special event &lt;em&gt;&amp;#8220;newListener&amp;#8221;&lt;/em&gt; is fired whenever you attach a new event listener. If you attach a listener to this &lt;em&gt;&amp;#8220;newListener&amp;#8221;&lt;/em&gt; event, it gets the events name and the function reference of the newly added listener:
&lt;pre&gt;function fnNewListener (eventName, fnListener) { }
myEventEmitter.on("newListener", fnNewListener );&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Note that if you &lt;em&gt;.emit()&lt;/em&gt; an event, its listener code is being executed synchroneously and then control goes back to the point where the event was emitted. Here is an example:
&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2818766" target="_blank"&gt;https://gist.github.com/2818766&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;

&lt;li&gt;Also note that within your event listener function, &lt;em&gt;this&lt;/em&gt; refers to the &lt;em&gt;EventEmitter&lt;/em&gt; object.
&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2818810" target="_blank"&gt;https://gist.github.com/2818810&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;Why the EventEmitter is awesome&lt;/h2&gt;

&lt;p&gt;You may ask yourself, why go through this trouble?&lt;/p&gt;

&lt;p&gt;The EventEmitter base functionality lets you easily create a &lt;strong&gt;commonly used&lt;/strong&gt; interface for other code to hook into. You can abstract much of the logic and only need to expose the events.&lt;/p&gt;

&lt;p&gt;Besides, many of the node.js core objects are based upon the EventEmitter, i.e. streams, the tcp/ip server and client, the http server and child processes. That alone should enable you to look further into it.&lt;/p&gt;

&lt;p&gt;Feel free to ask questions or comment below!&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/23925095762</link><guid>http://blog.gvm-it.eu/post/23925095762</guid><pubDate>Mon, 28 May 2012 14:10:52 +0200</pubDate><category>node.js</category><category>javascript</category><category>tutorial</category><category>how to</category></item><item><title>Extract newline seperated messages from a stream</title><description>&lt;p&gt;In &lt;a href="http://nodejs.org" target="_BLANK"&gt;node.js&lt;/a&gt;, you are often confronted with streams that you may want to send and recieve data over. The following post provides and explains a small helper function that allows you to extract newline-separated messages from a &lt;a href="http://nodejs.org/api/stream.html" target="_BLANK"&gt;node.js stream&lt;/a&gt;.&lt;/p&gt;
&lt;!-- more --&gt;

&lt;h2&gt;Why use this?&lt;/h2&gt;

&lt;p&gt;The problem with a stream is that you never know how much of a message has arrived. A common problem is that either only a part of the message arrived or multiple messages arrive at once. Therefore we separate each message with a newline character so we know when a message ends and when the next one begins.&lt;/p&gt;

&lt;p&gt;Here are a two example use cases for when you want to handle newline separated messages from a stream:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;You want to send strings or JSON-objects over a TCP/IP &lt;a href="http://nodejs.org/api/net.html" target="_BLANK"&gt;net&lt;/a&gt; connection.&lt;/li&gt;
&lt;li&gt;You want to handle the &lt;a href="http://nodejs.org/api/child_process.html#child_process_child_stdout" target="_BLANK"&gt;stdout stream from a child process&lt;/a&gt;, thus i.e. each console.log statement.&lt;/li&gt;
&lt;li&gt;You want to stream a file line by line.&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;The helper function&lt;/h2&gt;

&lt;p&gt;First the code, then the explanation:&lt;/p&gt;

&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2793677" target="_blank"&gt;https://gist.github.com/2793677&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;A stream emits a &lt;em&gt;data&lt;/em&gt; event whenever a &lt;em&gt;chunk&lt;/em&gt; of data arrives. The &lt;em&gt;chunk&lt;/em&gt; is added to a &lt;em&gt;buffer&lt;/em&gt; which in turn is check whether it includes our &lt;em&gt;newline delimiter \n&lt;/em&gt;. If so, a &lt;em&gt;piece&lt;/em&gt; of the &lt;em&gt;buffer&lt;/em&gt; is extracted, which now holds a complete message that is being sent to the &lt;em&gt;callback&lt;/em&gt; function. If no delimiter is found, wait until the next &lt;em&gt;chunk&lt;/em&gt; arrives and check again.&lt;/p&gt;

&lt;p&gt;Afterwards the &lt;em&gt;buffer&lt;/em&gt; is shortened by the length of the &lt;em&gt;piece&lt;/em&gt; and check whether it holds another complete message. If so, repeat, if not, wait for next chunk and start again.&lt;/p&gt;

&lt;p&gt;It must be noted that this function &lt;strong&gt;returns&lt;/strong&gt; an &lt;em&gt;EventListener function&lt;/em&gt;, it itself is not the function that listens for data events. So be sure to actually call the helper function.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/23791433751</link><guid>http://blog.gvm-it.eu/post/23791433751</guid><pubDate>Sat, 26 May 2012 14:04:00 +0200</pubDate><category>node.js</category><category>javascript</category><category>stream</category></item><item><title>Callback conventions in node.js, how and why</title><description>&lt;p&gt;When first confronted with &lt;a href="http://www.nodejs.org/" target="_BLANK"&gt;node.js&lt;/a&gt;, you are not only presented with a completely new programming environment. You also encounter what is often referred to as &lt;em&gt;callback hell&lt;/em&gt; accompanied by weird unfamiliar &lt;a href="http://en.wikipedia.org/wiki/Programming_pattern" target="_BLANK"&gt;programming patterns&lt;/a&gt;. One of these is the way node treats callback functions.&lt;/p&gt;

&lt;p&gt;The following post explains the conventions that node.js uses for its callback patterns (referred to as &lt;a href="http://en.wikipedia.org/wiki/Continuation-passing_style" target="_BLANK"&gt;Continuation-passing style&lt;/a&gt;) and how you should implement them in order to comply.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2&gt;The first argument is an error object&lt;/h2&gt;

&lt;p&gt;Node expects  - almost - all callback functions to accept an &lt;em&gt;Error object&lt;/em&gt; as the first argument. If no error occurred, the first argument should be &lt;em&gt;null&lt;/em&gt;. If you use inline anonymous functions, this is a typical code snippet that you will encounter using node:&lt;/p&gt;

&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2548942" target="_blank"&gt;https://gist.github.com/2548942&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;There is a reason why this is a usefull pattern: Imagine, you have a chain of asynchroneous functions that were to execute one after the other. I.e. read a file, get something out of a database, write something into the database and output the results to a callback function.&lt;/p&gt;

&lt;p&gt;Now think something went wrong in the first function, i.e. the file cannot be read. You don&amp;#8217;t want to blindly execute the other functions next in line. Instead, you skip the other functions and directly return to your callback function and let it choose how to handle the error. When no error occurred, continue with the next step.&lt;/p&gt;

&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2549029" target="_blank"&gt;https://gist.github.com/2549029&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;This pattern lets you waterfall through function chains and leaves handling the error it up to the original invoking function. It is likely that you do not want to throw uncaught errors all the time.&lt;/p&gt;

&lt;h2&gt;Pass error objects, not strings&lt;/h2&gt;

&lt;p&gt;While we&amp;#8217;re at it, when you create errors, you should create actual &lt;em&gt;Error objects&lt;/em&gt; that are passed around. When &lt;em&gt;Error objects&lt;/em&gt; are created, the JavaScript engine inserts additional information into them (i.e. the stack trace, file name, line number) that you can be useful for debugging.&lt;/p&gt;

&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2549052" target="_blank"&gt;https://gist.github.com/2549052&lt;/a&gt;&lt;/div&gt;

&lt;h2&gt;The last argument is the callback function&lt;/h2&gt;

&lt;p&gt;If your function expects a callback function as an argument, it should be the last argument. That callback function in turn should also accept an &lt;em&gt;Error object&lt;/em&gt; or &lt;em&gt;null&lt;/em&gt; as the first argument, as described above.&lt;/p&gt;

&lt;p&gt;Note that if you do not need a callback function, i.e. when you just don&amp;#8217;t perform asynchroneous actions, you don&amp;#8217;t forcefully need to demand one.&lt;/p&gt;

&lt;h2&gt;Additional and optional arguments go in between&lt;/h2&gt;

&lt;p&gt;Any more arguments, required or optional, should go in between the error and the callback parameter. Below is an example how you could retrieve the optional arguments:&lt;/p&gt;

&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2549131" target="_blank"&gt;https://gist.github.com/2549131&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Note that there other ways to check whether the optional arguments were supplied. This is just a very broad pattern that you can reuse.&lt;/p&gt;

&lt;h2&gt;When to apply these pattern fully&lt;/h2&gt;

&lt;p&gt;You don&amp;#8217;t always need to follow this pattern in detail. Use common sense to find out where to omit certain arguments.&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;When your function is the first in line of a longer chain of asynchroneous calls, it does not need to accept an &lt;em&gt;Error object&lt;/em&gt;. The next in line should though.&lt;/li&gt;

&lt;li&gt;When your function does not perform any asynchroneous calls and you can simply &lt;em&gt;return&lt;/em&gt; your result, you don&amp;#8217;t need to take a callback function.&lt;/li&gt;

&lt;li&gt;If your function returns multiple arguments and may fail, even though it is not asynchroneous, you may very well feed them to a callback function instead of stuffing them into a &lt;em&gt;return&lt;/em&gt; statement. This way your code is more readable - to node developers.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;The more node.js style code and API&amp;#8217;s you encounter, the more you will see that these patterns are used broadly among node libraries and modules and that it makes sense to use these.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/22040726249</link><guid>http://blog.gvm-it.eu/post/22040726249</guid><pubDate>Sun, 29 Apr 2012 12:26:00 +0200</pubDate><category>node.js</category><category>javascript</category><category>how to</category><category>tutorial</category><category>callback functions</category></item><item><title>Register all routes in a folder for your express server</title><description>&lt;p&gt;Given the following problem: You have an express based webserver and you have stored all your routes in seperate files in one folder, perhaps even organized into several subfolders. You now want an easy way to apply all routes with as little effort as possible..&lt;/p&gt;

&lt;p&gt;Meet &lt;a href="https://github.com/klovadis/node-walker" target="_BLANK"&gt;node-walker&lt;/a&gt;: This little module let&amp;#8217;s you crawl a subfolder and perform a callback on each filename that it encounters, including files in subdirectories.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m22dzxK4Wl1qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;The module can be installed through npm using &lt;em&gt;npm install node-walker&lt;/em&gt; or downloaded via the &lt;a href="https://github.com/klovadis/node-walker" target="_BLANK"&gt;GitHub page&lt;/a&gt;. Then just &lt;em&gt;require&lt;/em&gt; it and use it as documented on the GitHub page.&lt;/p&gt;

&lt;p&gt;You then pass &lt;em&gt;node-walker&lt;/em&gt; the directory which it should crawl and a callback function, which takes an &lt;em&gt;error object&lt;/em&gt; (in node fashion), the file name and a &lt;em&gt;next&lt;/em&gt; function as arguments. This callback function will be called for every filename it encounters, which you then can simply &lt;em&gt;require&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The example below shows the main script file that registers all routes that are stored in a subfolder called &lt;em&gt;/routes&lt;/em&gt; and an example &lt;em&gt;/routes/test.js&lt;/em&gt; file, that exports a &lt;em&gt;function register( [app] )&lt;/em&gt; in order to register itself with the express server instance.&lt;/p&gt;

&lt;div class="gist"&gt;&lt;a href="https://gist.github.com/2320816" target="_blank"&gt;https://gist.github.com/2320816&lt;/a&gt;&lt;/div&gt;</description><link>http://blog.gvm-it.eu/post/20642967017</link><guid>http://blog.gvm-it.eu/post/20642967017</guid><pubDate>Sat, 07 Apr 2012 11:01:31 +0200</pubDate><category>node.js</category><category>express</category><category>node-crawler</category><category>javascript</category><category>how to</category><category>tutorial</category></item><item><title>Iterate over all files in a folder in node.js: node-walker</title><description>&lt;a href="https://github.com/klovadis/node-walker"&gt;Iterate over all files in a folder in node.js: node-walker&lt;/a&gt;: &lt;p&gt;Use node-walker to recursively walk over a directory and all its files. You can then iterate over all filenames to i.e. require them all one after the other. Can be installed through npm as well: &lt;em&gt;npm install node-walker&lt;/em&gt;&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/20587906221</link><guid>http://blog.gvm-it.eu/post/20587906221</guid><pubDate>Fri, 06 Apr 2012 16:18:30 +0200</pubDate><category>node.js</category><category>npm</category></item><item><title>Getting started with MongoDB and node.js on Windows</title><description>&lt;p&gt;Earlier I wrote a little tutorial on &lt;a href="http://blog.gvm-it.eu/post/20404719601/getting-started-with-node-js-on-windows" target="_BLANK"&gt;how to get started with node.js on windows&lt;/a&gt;, which I now want to continue by explaining how to setup and use &lt;a href="http://www.mongodb.org/" target="_BLANK"&gt;MongoDB&lt;/a&gt; with &lt;a href="http://nodejs.org/" target="_BLANK"&gt;node.js&lt;/a&gt; in a Windows environment. This tutorial will cover:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Brief introduction to MongoDB&lt;/li&gt;
&lt;li&gt;Installation and setup of a MongoDB database server.&lt;/li&gt;
&lt;li&gt;Connecting to MongoDB using node and &lt;a href="https://github.com/christkv/node-mongodb-native" target="_BLANK"&gt;node-mongodb-native&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Basic database operations through node&lt;/li&gt;
&lt;/ul&gt;&lt;!-- more --&gt;&lt;h2&gt;What is MongoDB?&lt;/h2&gt;

&lt;p&gt;MongoDB is a non-relational database, a key-value store, also known as a NoSQL database, meaning that it strongly differs from traditional SQL databases.&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Data is stored as a JSON-like object in a &lt;em&gt;collection&lt;/em&gt;. Collections are the equivalent of SQL tables, but they are different.&lt;/li&gt;
&lt;li&gt;Unlike SQL databases, MongoDB is schema-free, meaning that you don&amp;#8217;t have to = cannot define a schema of your data in a particular collection. You programmatically choose to follow a certain format - or not.&lt;/li&gt;
&lt;li&gt;MongoDBs data format and command syntax is heavily based on JavaScript and JSON, meaning that you do not really need to learn a new query language, if you know JavaScript.&lt;/li&gt;
&lt;li&gt;NoSQL databases in general are a hot topic right now, both in a positive and a negative way. Keywords like scalability, reliability, stability and performance are discussed a lot, so it may or may not be the next big thing.&lt;/li&gt;
&lt;li&gt;Since MongoDBs interface is based on JavaScript and it takes and returns JSON-like objects, it works really well with node.&lt;/li&gt;
&lt;/ul&gt;&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1y9d2MbXc1qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;MongoDB offers a very great &lt;em&gt;online tutorial&lt;/em&gt; which gives you a taste of how MongoDB works and what it feels like. Just hit the &lt;em&gt;Try it out!&lt;/em&gt; button on the &lt;a href="http://www.mongodb.org/" target="_BLANK"&gt;MongoDB site&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Installation and setup&lt;/h2&gt;

&lt;p&gt;Installing MongoDB is ridiculously easy: Go to the &lt;a href="http://www.mongodb.org/downloads" target="_BLANK"&gt;Downloads section&lt;/a&gt; and grab either the 32bit or the 64bit distribution of MongoDB. It is served as a .zip file, which you just need to unzip into a folder of your liking.&lt;/p&gt;

&lt;p&gt;For demonstration purposes, let&amp;#8217;s assume that we unzipped everything into a folder &lt;em&gt;D:\mongodb&lt;/em&gt;. In order to launch MongoDB, we will use the command prompt (&lt;em&gt;Start&lt;/em&gt; -&amp;gt; &lt;em&gt;Run ..&lt;/em&gt; -&amp;gt; &lt;em&gt;cmd.exe&lt;/em&gt;). To run the database server, you need to start &lt;em&gt;mongod.exe&lt;/em&gt; which you find in your &lt;em&gt;D:\mongodb\bin&lt;/em&gt; folder.&lt;/p&gt;

&lt;p&gt;By default, a database is being created automatically in a &lt;em&gt;\mongodb\data&lt;/em&gt; subfolder, but let&amp;#8217;s assume that we want to choose our own database file which I recommend if you use multiple databases for different projects.&lt;/p&gt;

&lt;p&gt;For that, we need to pass a &lt;em&gt;&amp;#8212;dbpath&lt;/em&gt; argument. If we had our node.js app in &lt;em&gt;D:\node\myapp&lt;/em&gt;, we might want to save our data there in a subfolder called &lt;em&gt;data&lt;/em&gt;, so we need to launch MongoDB like this: &lt;em&gt;mongod &amp;#8212;dbpath D:\node\myapp\data&lt;/em&gt; which will look like this:&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1yajrG2111qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;Note: In order to shut down the database server, press &lt;em&gt;CTRL + C&lt;/em&gt; in the command prompt or just close it.&lt;/p&gt;

&lt;p&gt;You can simplify your database startup by writing your own little &lt;a href="http://en.wikipedia.org/wiki/Batch_file" target="_BLANK"&gt;batch file&lt;/a&gt; like this: Open up your favorite code editor and create a new file &lt;em&gt;run_database.bat&lt;/em&gt; and fill it with these contents:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;D:\mongodb\bin\mongod.exe --dbpath D:\node\myapp\data&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can double-click on that file to launch the database server conveniently. There are more startup options which can be seen if you type &lt;em&gt;mongod &amp;#8212;help&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note: By default, the MongoDB server does only accept connections from your local machine, but does not require any authentification. You can change these settings as shown in the &lt;a href="http://www.mongodb.org/display/DOCS/Home" target="_BLANK"&gt;official MongoDB documentation&lt;/a&gt;. For your local installation, we will stick to the defaults.&lt;/p&gt;

&lt;h2&gt;Connecting to MongoDB using node.js&lt;/h2&gt;

&lt;p&gt;Now for the fun part: In order to connect to a MongoDB-server, you need a database driver, which defaults to &lt;a href="https://github.com/christkv/node-mongodb-native" target="_BLANK"&gt;node-mongodb-native&lt;/a&gt;. Fire up your command prompt again, switch to your node.js app folder and install it using npm: &lt;em&gt;npm install mongodb&lt;/em&gt;&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1yb31yHiv1qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;Next, we will try and connect to the database. Copy the code below (taken from &lt;a href="http://christkv.github.com/node-mongodb-native/api-articles/nodekoarticle1.html" target="_BLANK"&gt;here&lt;/a&gt;) into your node program. Make sure the database server is running before you run it:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;var mongo = require('mongodb'),
  Server = mongo.Server,
  Db = mongo.Db;

var server = new Server('localhost', 27017, {auto_reconnect: true});
var db = new Db('exampleDb', server);

db.open(function(err, db) {
  if(!err) {
    console.log("We are connected");
  }
});&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If everything worked out, you will see the &lt;em&gt;We are connected!&lt;/em&gt; message in the node command prompt. After you are connected, you can then perform your database operations. Note that any commands are buffered until a connection is established or while the connection is interrupted.&lt;/p&gt;

&lt;h2&gt;Basic operations&lt;/h2&gt;

&lt;p&gt;Here I will introduce the most basic operations needed for your database tasks. For more specific information on operations and queries, you will need to read the &lt;a href="http://www.mongodb.org/display/DOCS/Querying" target="_BLANK"&gt;official documentation on querying&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Connecting and disconnecting&lt;/h3&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// include the mongodb module
var mongo = require('mongodb');

// create a server instance
var serverInstance = new mongo.Server('localhost', 27017, {auto_reconnect: true});

// retrieve a database reference
var dbref = new mongo.Db('myDatabaseName', serverInstance);

// connect to database server
dbref.open(function(err, dbref) {
    // now a connection is established
});

// close a database connection
dbref.close();
&lt;/code&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;// retrieve a collection reference
dbref.collection('myCollectionName', function(err, collectionref) { 
    // this is an asynchroneous operation
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note: If you try and use a collection that does not exist, an empty collection is automatically being created.&lt;/p&gt;

&lt;h3&gt;Insert documents&lt;/h3&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// insert a document into a collection
var myDoc = {"some":"data", "foo":"bar"};
collectionref.insert(myDoc, function (err, result) {
    // this is an asynchroneous operation
});
// insert multiple documents
var myDocs = [{"foo":"bar"}, {"foo":"bar2"}, {"foo":"bar3"}];
collectionref.insert(myDocs, function (err, result) {
    // this is an asynchroneous operation
});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note: ObjectID&amp;#8217;s are generated automatically, you don&amp;#8217;t need to do that manually.&lt;/p&gt;

&lt;h3&gt;Querying documents&lt;/h3&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// find all documents in a collection
var cursor = collectionref.find();
cursor.toArray(function(err, docs) {
    // gets executed once all items are retrieved
});

// find all documents in a collection that have foo: "bar"
var cursor = collectionref.find({foo:"bar"});
cursor.toArray(function(err, docs) {
    // gets executed once all items are retrieved
});

// find exactly one item in a collection which has foo:"bar"
collectionref.findOne({foo:"bar"}, function(err, doc) {
    // no cursor object is needed
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Returning partial results: sort, skip, limit&lt;/h3&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// find all documents in a collection
var cursor = collectionref.find();

// sort the result by the "foo" field, ascending
cursor.sort([["foo", 1]]);

// skip any amount of results, i.e. for pagination
cursor.skip(10);

// only retrieve a specified amount of results
cursor.limit(10, function (err, cursor) {
    // no documents are provided, that must follow afterwards
});

// then retrieve results as an array
cursor.toArray(function(err, docs) {
    // gets executed once all items are sorted and retrieved
});

// .. or retrieve results one after the other
cursor.each( function (err, doc) {
    // doc === null when this function has shown all documents
    // otherwise doc will hold the current document
});

// count the number of results
cursor.count(function (err, amount) {
    // amount will hold the number of results
});

// if you only need the count and no results, use this instead
collectionref.count({foo:"bar"}, function (err, amount) {
    // amount will hold the number of matches
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Removing documents&lt;/h3&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// Remove all the documents in a collection
collectionref.remove();

// remove all documents that match a condition
collectionref.remove({foo:"bar"});

// execute a callback afterwards
collectionref.remove(function (err) {
    // all documents have been removed
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Updating documents&lt;/h3&gt;

&lt;p&gt;The syntax is &lt;em&gt;update(selector, document[, options][, callback])&lt;/em&gt;, where you need to specify &lt;em&gt;multi&lt;/em&gt; in the options to &lt;em&gt;true&lt;/em&gt; if you wish to update all matched documents. You may also specify &lt;em&gt;upsert&lt;/em&gt; to &lt;em&gt;true&lt;/em&gt; if you want to create a new document if none is found to update.&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;// replace the foo field on all objects where foo:"bar"
collectionref.update({foo:"bar", {foo:"zoo"}, {multi:true}, function (err) {
    // operation has been performed
});
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Further reading&lt;/h2&gt;

&lt;p&gt;More information on querying and the methods provided can be found &lt;a href="http://christkv.github.com/node-mongodb-native/api-articles/nodekoarticle1.html" target="_BLANK"&gt;here&lt;/a&gt; in general and more specific in the &lt;a href="http://christkv.github.com/node-mongodb-native/api-generated/collection.html" target="_BLANK"&gt;Collection&lt;/a&gt; and &lt;a href="http://christkv.github.com/node-mongodb-native/api-generated/cursor.html" target="_BLANK"&gt;Cursor&lt;/a&gt; API documentation of the node driver.&lt;/p&gt;

&lt;p&gt;There also exists an abstraction layer for MongoDB called &lt;a href="https://github.com/LearnBoost/mongoose" target="_BLANK"&gt;Mongoose&lt;/a&gt;; This module allows you to abstract database interaction to a certain extent providing you with the ability to enforce a schema onto MongoDB databases and add validation functions to operations, but I recommend becoming familiar with vanilla MongoDB before you try it out.&lt;/p&gt;

&lt;p&gt;Also I strongly recommend diving into the &lt;a href="http://www.mongodb.org/display/DOCS/Home" target="_BLANK"&gt;official documentation of MongoDB&lt;/a&gt; if you want to really get to know MongoDB.&lt;/p&gt;

&lt;p&gt;If you find yourself ending up in &lt;em&gt;callback hell&lt;/em&gt;, you may want to have a look at &lt;em&gt;flow control libraries&lt;/em&gt; for node.js, i.e. my very own &lt;a href="https://github.com/klovadis/kloflow" target="_BLANK"&gt;kloflow&lt;/a&gt; module.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/20462477195</link><guid>http://blog.gvm-it.eu/post/20462477195</guid><pubDate>Wed, 04 Apr 2012 13:42:00 +0200</pubDate><category>MongoDB</category><category>Windows</category><category>node.js</category><category>tutorial</category><category>how to</category></item><item><title>Getting started with node.js on Windows</title><description>&lt;p&gt;The following tutorial will give you a very brief guide on how to get started with node.js on Windows. This tutorial will not tell you which third-party tools to use, this is just a plain introduction to the node.js ecosystem. This includes:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Install and setup node.js on windows.&lt;/li&gt;
&lt;li&gt;Run a &amp;#8220;Hello world!&amp;#8221;-program.&lt;/li&gt;
&lt;li&gt;Create a webserver program.&lt;/li&gt;
&lt;li&gt;Use npm to install a module.&lt;/li&gt;
&lt;/ul&gt;&lt;!-- more --&gt;&lt;h2&gt;Installation&lt;/h2&gt;

&lt;p&gt;Recently it has become much easier to install node.js on Windows. Forget cygwin and virtual linux boxes or anything else. Just go to &lt;a href="http://www.nodejs.org/" target="_BlANK"&gt;nodejs.org&lt;/a&gt; and hit the &lt;a href="http://nodejs.org/#download" target="_BLANK"&gt;Download&lt;/a&gt; link. You will be presented with different packages as shown below; Pick the Microsoft Installer.&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1whmsT4pQ1qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;After downloading, simply run the .msi file which will guide you through the installation pretty straightforward. There are no options to check; Node installs into &lt;em&gt;C:\Program Files (x86)\nodejs&lt;/em&gt; and adds itself to the &lt;em&gt;PATH&lt;/em&gt; variable.&lt;/p&gt;

&lt;p&gt;Note that since we&amp;#8217;re running on a Microsoft operating system, the obligatory reboot is necessary to make the change to the &lt;em&gt;PATH&lt;/em&gt; variable take effect, meaning you can just type &lt;em&gt;node&lt;/em&gt; into your command prompt instead of having to type the full path. So.. reboot now.&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1wi6xudh31qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;After the installation and an annoying reboot, we will test whether the installation worked. Open up a command prompt (&lt;em&gt;Start&lt;/em&gt; -&amp;gt; &lt;em&gt;Run ..&lt;/em&gt; -&amp;gt; &lt;em&gt;cmd.exe&lt;/em&gt;), type &lt;em&gt;node&lt;/em&gt; and hit &lt;em&gt;enter&lt;/em&gt;. 

&lt;/p&gt;&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1wi7sXaO51qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;If the installation succeeded, you are now in the command line mode of node.js, meaning you can code on the fly. We are not going to do that right now, we just wanted to see whether it worked. For now, press &lt;em&gt;CTRL + C&lt;/em&gt; twice to quit.&lt;/p&gt;

&lt;p&gt;Note: You can exit any running node process by pressing &lt;em&gt;CTRL + C&lt;/em&gt; in the corresponding command window.&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1wiiyCCHZ1qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;Congratulation, you successfully installed node.js on your Windows computer.&lt;/p&gt;

&lt;h2&gt;Hello world?!&lt;/h2&gt;

&lt;p&gt;Any text file can be interpreted by node, so fire up your favorite text / code editor and create a new file &lt;em&gt;helloworld.js&lt;/em&gt;. In that file, put the following contents:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;// our very first node program
console.log("Hello world!");&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note: &lt;em&gt;console.log( [string] )&lt;/em&gt; let&amp;#8217;s you write messages to stdout, meaning they show up in your command prompt. This is useful for debugging.&lt;/p&gt;

&lt;p&gt;Next we of course need to run our script using node. Open up your command prompt again as shown before and go to the directory in which you placed your &lt;em&gt;helloworld.js&lt;/em&gt; file. Then type &lt;em&gt;node helloworld.js&lt;/em&gt; and hit &lt;em&gt;enter&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;If your file was placed in &lt;em&gt;D:\node\helloworld.js&lt;/em&gt;, type the following commands one after the other:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;d:&lt;/li&gt;
&lt;li&gt;cd node&lt;/li&gt;
&lt;li&gt;node helloworld.js&lt;/li&gt;
&lt;/ul&gt;&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1wj43iknh1qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;Note: Any node program quits as soon as there is nothing left to compute or there is no event left to wait for. In this case, after writing the &lt;em&gt;Hello world!&lt;/em&gt; message, there is nothing left to do.&lt;/p&gt;

&lt;p&gt;Note: You need to restart your node program whenever you change something in the source code.&lt;/p&gt;

&lt;p&gt;Next we will try out the &lt;em&gt;Hello world!&lt;/em&gt; example from the &lt;a href="http://www.nodejs.org/" target="_BLANK"&gt;nodejs.org&lt;/a&gt; website. Replace the contents of the &lt;em&gt;helloworld.js&lt;/em&gt; file with the following code:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;// include the http module
var http = require('http');

// create a webserver
http.createServer(function (req, res) {

    // respond to any incoming http request
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');

}).listen(1337, '127.0.0.1');

// log what that we started listening on localhost:1337
console.log('Server running at 127.0.0.1:1337');
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the command prompt, type &lt;em&gt;node helloworld.js&lt;/em&gt; again and hit &lt;em&gt;enter&lt;/em&gt; again, which will present you with the following:&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1wjechWv01qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;Note: At this point, your firewall will propably tell you that node is trying to access network functionality.&lt;/p&gt;

&lt;p&gt;This means that your newly created webserver is listening on &lt;a href="http://localhost:1337/" target="_BLANK"&gt;http://localhost:1337/&lt;/a&gt;, so type that adres in your browser and see the following:&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1wjhmNOf31qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;Congratulations, again! You just wrote your very own webserver in node!&lt;/p&gt;

&lt;p&gt;Note: Type &lt;em&gt;CTRL + C&lt;/em&gt; to shut down the node program.&lt;/p&gt;

&lt;h2&gt;Using npm on windows&lt;/h2&gt;

&lt;p&gt;Node comes with a packages manager, &lt;a href="http://npmjs.org/" target="_BLANK"&gt;node package manager (npm)&lt;/a&gt;, which is automatically installed along node. To use npm, you need to open a command prompt, switch to the directory in which you want to use it, and type &lt;em&gt;npm&lt;/em&gt; plus the command you with to execute.&lt;/p&gt;

&lt;p&gt;Node&amp;#8217;s core functionality is very slim, but there is a very large number of libraries - in node they are called &lt;em&gt;modules&lt;/em&gt; - which you can use. Npm is a very powerfull tool and the libraries which you may use are countless, so I will just show how to locally install a module for your current project.&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;em&gt;cd&lt;/em&gt; to your program directory (as shown above).&lt;/li&gt;
&lt;li&gt;type: &lt;em&gt;npm install express&lt;/em&gt; to install the &lt;a href="http://expressjs.com" target="_BLANK"&gt;express web framework&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Hit &lt;em&gt;enter&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;You should see something like the following:&lt;/p&gt;

&lt;p style="text-align:center;"&gt;&lt;img src="http://media.tumblr.com/tumblr_m1wk2emxa91qekfnu.png"/&gt;&lt;/p&gt;

&lt;p&gt;A new folder &lt;em&gt;node_modules&lt;/em&gt; has been created in your &lt;em&gt;D:\node&lt;/em&gt; directory. It will also hold all future modules that you install for your current project using &lt;em&gt;npm&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You may now use the &lt;em&gt;express&lt;/em&gt; module by requiring it, as shown in this simple example:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;var express = require('express');

var app = express.createServer();

app.get('/', function(req, res){
    res.send('Hello World');
});

app.listen(1337);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can run this code in the same way as the other &lt;em&gt;Hello world!&lt;/em&gt; - examples. For more practical uses and a whole explanation of the express-framework, visit its site at &lt;a href="http://expressjs.com/" target="_BLANK"&gt;expressjs.com&lt;/a&gt; or google for some examples.&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;You are now able to use &lt;em&gt;node.js&lt;/em&gt; and &lt;em&gt;npm&lt;/em&gt; on your Windows-computer. You can now skip ahead to more advanced tutorials or you can start reading the &lt;a href="http://nodejs.org/api/" target="_BLANK"&gt;node code api documentation&lt;/a&gt;, which I strongly recommend before learning any framework.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/20404719601</link><guid>http://blog.gvm-it.eu/post/20404719601</guid><pubDate>Tue, 03 Apr 2012 14:09:00 +0200</pubDate><category>node.js</category><category>windows</category><category>tutorial</category><category>how to</category></item><item><title>Plain Text Copy And Paste - Google Chrome Extension</title><description>&lt;p&gt;I came to the realisation that I get mad whenever I accidently paste formatted text and that I am too lazy to use CTRL + SHIFT + V, so I wrote a tiny Google Chrome extension that removes formatting and markup information from text that you copy to your clipboard: &lt;a href="https://chrome.google.com/webstore/detail/fopopdnfchicbemjodbnnjdkpndfhoje" target="_BLANK"&gt;Plain Text Copy And Paste&lt;/a&gt;&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p&gt;I recently have to do a lot of copy and paste work from websites to &lt;a href="http://www.openoffice.org/" target="_BLANK"&gt;OpenOffice Calc&lt;/a&gt; and I lose my mind whenever the table cells contain styling that I did not mean to paste. Again, I am too lazy to use CTRL + SHIFT + V to &amp;#8220;&lt;em&gt;paste special&lt;/em&gt;&amp;#8221; without formatting - especially since OpenOffice shows another selection dialogue (&lt;em&gt;rant: Why on earth show a selection dialogue if there is only one item to choose from?!&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;The source code of this extension can be found on GitHub: &lt;a href="https://github.com/klovadis/Plain-Text-Copy-And-Paste/blob/master/script.js" target="_BLANK"&gt;klovadis / Plain-Text-Copy-And-Paste&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;How this extension works&lt;/h2&gt;

&lt;p&gt;Here&amp;#8217;s the technical explanation on how the extension works: After the initialisation of the document the &lt;a href="https://github.com/klovadis/Plain-Text-Copy-And-Paste/blob/master/script.js" target="BLANK"&gt;script.js&lt;/a&gt; file gets injected into each and every page that you visit. See the &lt;a href="https://github.com/klovadis/Plain-Text-Copy-And-Paste/blob/master/manifest.json" target="_BLANK"&gt;manifest.json&lt;/a&gt; file, lines 5 through 12. Also note that the script file is executed in its own scope, &lt;a href="http://code.google.com/chrome/extensions/content_scripts.html#execution-environment" target="_BLANK"&gt;as explained here&lt;/a&gt;, that&amp;#8217;s why the injection does not take place in an anonymous function.&lt;/p&gt;

&lt;p&gt;When the script is run, it adds an event listener to the body that listens for the &amp;#8220;&lt;em&gt;keydown&lt;/em&gt;&amp;#8221; event, thus when a keyboard key is pressed. If CTRL + C is pressed, the magic happens: A hidden textarea is created and selected, which holds the plain text version of the currently selected text. After about 100ms the textarea is being hidden again.&lt;/p&gt;

&lt;p&gt;After executing the event listener function, Chrome proceeds to do what it is supposed to do, when CTRL + C is pressed: Copying the selected text to the clipboard. However, we changed the selection before this could happen. So by selecting text in a textarea, we got rid of any style information&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/14992846001</link><guid>http://blog.gvm-it.eu/post/14992846001</guid><pubDate>Fri, 30 Dec 2011 00:33:55 +0100</pubDate></item><item><title>Bookmark Buttons Startpage update 1.2.2</title><description>&lt;a href="https://chrome.google.com/webstore/detail/genmiebglliamphdcfeakonfebajldkj"&gt;Bookmark Buttons Startpage update 1.2.2&lt;/a&gt;: &lt;p&gt;I just updated the &lt;a href="https://chrome.google.com/webstore/detail/genmiebglliamphdcfeakonfebajldkj" target="_BlANK"&gt;Bookmark Buttons Startpage&lt;/a&gt; to version 1.2.2 which fixes a problem that is recognized by the current version of Google Chrome, but not by the previous ones. Also the webstore presentation was updated in order to comply with the new formats.&lt;/p&gt;

&lt;p&gt;The extension should update automatically over the next days, but you can manually update it if you go to the extension management window and hit the “&lt;i&gt;Update all extensions&lt;/i&gt;” button.&lt;/p&gt;

&lt;p&gt;As a sidenote: Chrome 15 does now throw a fatal error when a new RegExp object is created with unrecognized / invalid flags. Turns out that JavaScript does not support the /s flag.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/12283108369</link><guid>http://blog.gvm-it.eu/post/12283108369</guid><pubDate>Thu, 03 Nov 2011 14:36:04 +0100</pubDate></item><item><title>Simple template wrapper for NodeJS</title><description>&lt;a href="https://github.com/klovadis/Templates"&gt;Simple template wrapper for NodeJS&lt;/a&gt;: &lt;p&gt;I rewrote a solution by &lt;a href="http://ejohn.org/" target="_BLANK"&gt;John Resig&lt;/a&gt; to create simple templates in JavaScript to work with node.js and added support for file loading and inline templates. Check out the examples for more information.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/11226689621</link><guid>http://blog.gvm-it.eu/post/11226689621</guid><pubDate>Sun, 09 Oct 2011 16:29:13 +0200</pubDate></item><item><title>Node.js 0.5.2 - Load JSON files with require</title><description>&lt;p&gt;Just a brief post: With the latest release of &lt;a href="http://www.nodejs.org" target="_blank"&gt;node.js&lt;/a&gt;, it is now possible to load files that only contain JSON data directly into objects using the &lt;em&gt;require( [path_to_file] )&lt;/em&gt; function.&lt;/p&gt;
&lt;!-- more --&gt;
&lt;p&gt;Before, you had to use a function like this to achieve the same:&lt;/p&gt;&lt;pre&gt;&lt;code class="javascript"&gt;// a function to load json data from a file
var fs = require('fs');
function loadJSONfile (filename, encoding) {
	try {
		// default encoding is utf8
		if (typeof (encoding) == 'undefined') encoding = 'utf8';
		
		// read file synchroneously
		var contents = fs.readFileSync(filename, encoding);

		// parse contents as JSON
		return JSON.parse(contents);
		
	} catch (err) {
		// an error occurred
		throw err;	
	}
} // loadJSONfile


// this is what we needed to do now
var myData = loadJSONfile(__dirname + '/data.json');
console.log('loadJSONfile:', myData);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As of node.js 0.5.2 we can simply do the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// this is possible as of node.js 0.5.2
var myData = require('./data.json');
console.log('Require:', myData);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It is also noteworthy that the &lt;em&gt;require&lt;/em&gt; statement will also cache the result of loading that JSON file, meaning that you can refer to it from many files / modules without having to process it each and every time.&lt;/p&gt;

&lt;p&gt;In other words, this will make storing static data in files locally much, much more attractive.&lt;/p&gt;

&lt;h2&gt;Full Changelog&lt;/h2&gt;

&lt;p&gt;For the full changelog, visit &lt;a href="http://blog.nodejs.org/2011/07/22/node-v0-5-2/" target="_blank"&gt;the node.js blog&lt;/a&gt;. As of node.js 0.5.0, there also is an official Windows &lt;a href="http://nodejs.org/dist/v0.5.2/" target="_blank"&gt;node.exe&lt;/a&gt; file, which allows Windows users to use node without running a virtual machine or build it using CygWin.&lt;/p&gt;

&lt;p&gt;Unfortunately, however, that executable comes withoutthe &lt;a href="http://npmjs.org/" target="_blank"&gt;Node Package Manager&lt;/a&gt;, meaning that you painfully have to install libraries manually. For that reason, I&amp;#8217;m still running an older version that includes &lt;em&gt;NPM&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;According to &lt;a href="http://nodejs.org/oscon.pdf" target="_blank"&gt;Ryan Dahl&amp;#8217;s slides&lt;/a&gt; at OSCOM 2011, the next major release, node.js 0.6.0 is been schedulded to arrive within four weeks. &lt;em&gt;NPM&lt;/em&gt;, however, was not mentioned.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/8175813806</link><guid>http://blog.gvm-it.eu/post/8175813806</guid><pubDate>Thu, 28 Jul 2011 18:56:00 +0200</pubDate></item><item><title>My very own Flow Control module</title><description>&lt;a href="https://github.com/klovadis/kloflow"&gt;My very own Flow Control module&lt;/a&gt;: &lt;p&gt;While toying around with Node.js, I ended up writing my own little flow control library. Check it out on GitHub and leave a comment!&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/8062378736</link><guid>http://blog.gvm-it.eu/post/8062378736</guid><pubDate>Tue, 26 Jul 2011 01:55:10 +0200</pubDate></item><item><title>Inspired by a link on Google+ that explained how to run Chrome...</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_lojrb8FvIl1qfcms0o1_400.png"/&gt;&lt;br/&gt; Browsing did feel a little slow ..&lt;br/&gt;&lt;br/&gt; &lt;img src="http://25.media.tumblr.com/tumblr_lojrb8FvIl1qfcms0o2_500.jpg"/&gt;&lt;br/&gt; Bookmark Buttons Startpage on Chromium&lt;br/&gt;&lt;br/&gt; &lt;p&gt;Inspired by a link on Google+ that explained &lt;a href="http://www.zeropaid.com/news/94384/how-to-run-googles-chrome-os-from-a-usb-drive/" target="_BLANK"&gt;how to run Chrome OS from a usb drive&lt;/a&gt; I gave Chromium a try. I did encounter a few glitches (y u no recognize my usb mouse?!) and browsing felt a little slow, but apart from that I really like Google Chrome OS on my laptop.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/7773765480</link><guid>http://blog.gvm-it.eu/post/7773765480</guid><pubDate>Mon, 18 Jul 2011 22:52:00 +0200</pubDate></item><item><title>How to: Heredocs in JavaScript</title><description>&lt;p&gt;The following code allows you to define multi line strings in your JavaScript code. However, it is not cross-browser compatible - some implementations will return empty strings. So why bother? Because the V8 engine - thus node.js - does support this dirty hack!&lt;/p&gt;
&lt;!-- more --&gt;
&lt;p&gt;Include the following function somewhere in your code:&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;function heredoc(func) {
	// get function code as string
	var hd = func.toString();
	
	// remove { /* using a regular expression
	hd = hd.replace(/(^.*\{\s*\/\*\s*)/g, '');
	
	// remove */ } using a regular expression
	hd = hd.replace(/(\s*\*\/\s*\}.*)$/g, '');
	
	// return output
	return hd;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Define a template like this - note that we use an empty function where we put our heredoc string into a Javascript comment which gets stripped out:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;var myTemplate = function() { /*

&amp;lt;html&amp;gt;
	&amp;lt;body&amp;gt;
		&amp;lt;h1&amp;gt;This is a template&amp;lt;/h1&amp;gt;
	&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

*/ }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can get the heredocs contents using heredoc(myTemplate):&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;var myHeredocString = heredoc(myTemplate);
console.log(myHeredocString);

// output:

&amp;lt;html&amp;gt;
	&amp;lt;body&amp;gt;
		&amp;lt;h1&amp;gt;This is a template&amp;lt;/h1&amp;gt;
	&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/7686382723</link><guid>http://blog.gvm-it.eu/post/7686382723</guid><pubDate>Sat, 16 Jul 2011 14:54:42 +0200</pubDate><category>javascript</category><category>node.js</category></item><item><title>HTML5 vs Native apps from the viewpoint of Diary.com</title><description>&lt;a href="http://eu.techcrunch.com/2011/07/12/guest-post-why-we-chose-html5-over-native-apps/"&gt;HTML5 vs Native apps from the viewpoint of Diary.com&lt;/a&gt;: &lt;p&gt;I’ve been doing some testing for &lt;a href="http://www.diary.com/" target="_blank"&gt;Diary.com&lt;/a&gt; over the past few months. In this article, they describe their take on choosing between using HTML5 technologies over native code when creating their mobile app.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/7648051569</link><guid>http://blog.gvm-it.eu/post/7648051569</guid><pubDate>Fri, 15 Jul 2011 12:50:00 +0200</pubDate></item><item><title>How to: Enable syntax highlighting on your Tumblr blog</title><description>&lt;a href="http://drnicwilliams.com/2007/03/08/syntax-highlighting-in-tumblr/"&gt;How to: Enable syntax highlighting on your Tumblr blog&lt;/a&gt;: &lt;p&gt;&lt;a href="http://drnicwilliams.com" target="_BLANK"&gt;Dr. Nic Williams&lt;/a&gt; has created a simple and easy to use plugin to Tumblr which allows coders to use syntax highlighting in their blog posts. Read his (&lt;em&gt;4 year old&lt;/em&gt;) article on &lt;a href="http://drnicwilliams.com/2007/03/08/syntax-highlighting-in-tumblr/" target="_BLANK"&gt;syntax highlighting in Tumblr&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/6528702634</link><guid>http://blog.gvm-it.eu/post/6528702634</guid><pubDate>Tue, 14 Jun 2011 21:25:00 +0200</pubDate></item><item><title>Keyboard input module for node: node-prompt.js</title><description>&lt;p&gt;I have been watching node.js very close over the past weeks and eventually got myself a working installation, so it was about time to code something. But what? Don&amp;#8217;t ask why, but I ended up writing a simple module that allows you to prompt input in your node process window.&lt;/p&gt;&#13;&lt;!-- more --&gt;
&lt;p&gt;Basically, what I wanted to have was the possibility to start up a node.js program and manually enter data without having to pass it via the command line. For example, one might want to enter a server adres or a password when you fire up your script.&lt;/p&gt;
&lt;p&gt;In the example below, the program asks for your favorite color and a secret, which does not display the text that you entered:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lmhh1eM5W21qekfnu.png"/&gt;&lt;/p&gt;
&lt;p&gt;The corresponding code (&lt;em&gt;example.js&lt;/em&gt; in the &lt;a title="node-prompt.js.zip" href="http://www.gvm-it.eu/apps/node-prompt.js.zip" target="_blank"&gt;.zip package&lt;/a&gt;) looks something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// include node-prompt.js
var nodePrompt = require('./node-prompt.js');

// open an input prompt
nodePrompt.prompt(
	"What is your favorite color?", 
	function(response) {
	
		// print the entered text
		console.log(response + " really is a nice color.");
		
		// example asking for a password
		nodePrompt.password(
			"Now tell me a secret!", 
			function(password) {
			
				// print out the entered text
				console.log("Did you hear that? " 
					+ password.toUpperCase() 
					+ "! That\'s just ridiculous!");
		});
});&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The sourcecode for &lt;em&gt;node-prompt.js&lt;/em&gt; is included in this &lt;a title="node-prompt.js" href="http://www.gvm-it.eu/apps/node-prompt.js.zip" target="_blank"&gt;node-prompt.js.zip&lt;/a&gt; (2.4kb) package. Extract it anywhere and run &lt;em&gt;example.js&lt;/em&gt; with node. If this is something which node users find useful, I will eventually create a npm package for it, but for now I&amp;#8217;ll rest with it.&lt;/p&gt;
&lt;p&gt;Feedback is appreciated!&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/6325759603</link><guid>http://blog.gvm-it.eu/post/6325759603</guid><pubDate>Wed, 08 Jun 2011 20:17:00 +0200</pubDate><category>node.js</category><category>node-prompt.js</category><category>javascript</category></item><item><title>Creating my first iPhone webapp: Pulse Meter</title><description>&lt;p&gt;I have finally found something to turn into a more or less usefull webapp for the iPhone: A pulse meter which allows to quickly fetch a persons pulse. You can try the app by opening &lt;a title="Pulse Meter webapp" target="_blank" href="http://www.gvm-it.eu/apps/pulse.html"&gt;this link&lt;/a&gt;. Below there is a brief introduction and a user manual.&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;The reason why I came up with this is the following: In the hospital, from time to time, you need to manually take a patients pulse. Usually you would take any watch and count the heartbeats that occur within fifteen seconds and multiply that number by four. For me as an intern, not having a wristwatch, this quick task is quite a hassle because I need to fire up the stopwatch on my iPhone.&lt;/p&gt;
&lt;p&gt;The app I created simplifies this task:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Find a patients pulse.&lt;/li&gt;
&lt;li&gt;Open the app.&lt;/li&gt;
&lt;li&gt;With every heartbeat, tap on the screen.&lt;/li&gt;
&lt;li&gt;After about 10 heartbeats, you get the patients pulse accurately displayed on the phone&amp;#8217;s screen.&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;&lt;img align="middle" src="http://media.tumblr.com/tumblr_ljybjgdJ9U1qekfnu.png"/&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s how you can get the app (free):&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Open up Safari on your iPhone, iPod or iPad.&lt;/li&gt;
&lt;li&gt;Go to the following adres: &lt;a title="Pulse Meter webapp" target="_blank" href="http://www.gvm-it.eu/apps/pulse.html"&gt;&lt;a href="http://www.gvm-it.eu/apps/pulse.html" target="_blank"&gt;http://www.gvm-it.eu/apps/pulse.html&lt;/a&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Start tapping!&lt;/li&gt;
&lt;li&gt;You can add this app to your home screen by hitting the bookmark-icon in Safari and then choosing to &amp;#8216;&lt;em&gt;Add to home screen&amp;#8217;.&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;As an intern, this app is really helpfull to me. Creating it was very simple with a little help from Matt Might&amp;#8217;s tutorial &lt;a title="HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript" target="_blank" href="http://matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/"&gt;HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Any feedback is appreciated!&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/4775268087</link><guid>http://blog.gvm-it.eu/post/4775268087</guid><pubDate>Wed, 20 Apr 2011 14:56:14 +0200</pubDate></item><item><title>Bookmark Buttons Startpage v1.2.1 released</title><description>&lt;p&gt;I just released the new version of the &lt;a title="Bookmark Buttons Startpage, a new tab replacement for Google Chrome" href="https://chrome.google.com/webstore/detail/genmiebglliamphdcfeakonfebajldkj" target="_blank"&gt;Bookmark Buttons Startpage&lt;/a&gt;. This is a minor update which fixes an annoying glitch and provides a few new features. You may need to manually update the extension from the extensions menu, otherwise Google may take its time to do so automatically.&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;The following things have been changed:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;The behaviour of opening links has changed and thereby fixes the issue that the bookmark URL would not appear in the adres bar of the extension. Thank you everyone for reporting this problem!&lt;/li&gt;
&lt;li&gt;Folder can now be opened in new windows using middle-click and in most cases, you can use the browsers built-in back button to go browse back.&lt;/li&gt;
&lt;li&gt;A donations section has been added. I am just curious to see if it does appeal to anyone, but of course I am not mad if it does not.&lt;/li&gt;
&lt;li&gt;You can now disable the bottom or top box if through the options dialogue. Shout-out to BC-1986 for pointing this out.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;This is what the page looks like if you disable the Bookmark bar or the Other bookmarks section:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_li9ej3qJPA1qekfnu.png"/&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the top box is empty except for the Chrome links. This only works if you don&amp;#8217;t use any apps.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_li9ejdCOs71qekfnu.png"/&gt;&lt;/p&gt;
&lt;p&gt;This can also be done the other way around. Note that I picked an unsorted folder in order to show an example of a long list of bookmarks, that&amp;#8217;s why the titles are so long. It will also display apps if there are any.&lt;/p&gt;
&lt;p&gt;Like it? Hate it? Leave me a comment&amp;#160;: ) Also, I appreciate any bug reports!&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/3941099300</link><guid>http://blog.gvm-it.eu/post/3941099300</guid><pubDate>Fri, 18 Mar 2011 16:23:42 +0100</pubDate></item><item><title>Coming soon: Version 1.2.1 of the Bookmark Button Startpage</title><description>&lt;p&gt;I am about to release the next minor version of the &lt;a title="Bookmark Buttons Startpage in Chrome Webstore" href="https://chrome.google.com/webstore/detail/genmiebglliamphdcfeakonfebajldkj" target="_blank"&gt;Bookmark Button startpage&lt;/a&gt; which fixes an annoying bug which rose with version 10 of the Google Chrome webbrowser.&lt;!-- more --&gt;&lt;/p&gt;
&lt;p&gt;The problem was the following: Whenever you would open a bookmark, app or just any link on the page, the adres bar at the top of the tab would not display the adres where you were at. This is mostly a cosmetic problem, but still a nuisance. With the fix, the adresses should be shown properly again.&lt;/p&gt;
&lt;p&gt;Also I added a new section in the extension options pages for donations. Apart from that, I fixed a small inconsistency in the page CSS and added a new theme which I labelled &lt;em&gt;Plain Grey&lt;/em&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img height="275" width="400" alt="Plain Grey theme by Geerten van Meel" src="http://www.gvm-it.eu/bbstartpage/themes/preview/plain_grey.png"/&gt;&lt;/p&gt;
&lt;p&gt;I will take my time to search and fix further bugs which I may have created afterwards. Over the next couple of days the update will take place and automatically roll to users.&lt;/p&gt;</description><link>http://blog.gvm-it.eu/post/3835122250</link><guid>http://blog.gvm-it.eu/post/3835122250</guid><pubDate>Sun, 13 Mar 2011 19:04:52 +0100</pubDate></item></channel></rss>

