In the new version 2 of Smart Mobile Studio you can now create server side projects! This is possible by using node.js, which is “the next big thing”: It’s an event based server side JavaScript application using the open source and very fast Google’s V8 engine. It was initially developed to be used as a HTTP server in the cloud, but nowadays you can also use it on your own PC or on a business server. It is powered by a small executable (6 MB) which doesn’t need an installation. Still, it can be extended easily via the package manager npm to fulfill any desired purpose and make it versatile in a lot different situations. For example, it is used by LinkedIn, WalMart and even Microsoft(!) in the Azure cloud. Also, PayPal has recently switched from Java to Node.js…
When you start using node.js, be aware that it is very different to web browser programming: it is a server with no GUI, so no ‘document’ and ‘window’ globals and no ‘alert’ function. It doesn’t run in a sandbox so you access all files, databases etc like you can with a normal application. It has it’s own API for this, which cannot be compared to “JavaScript for HTML”: it is just JavaScript and has nothing to do with web browsers.
But be aware: it is fun and addictive! 🙂
Enough theory, let’s create a new server project in Smart Mobile Studio 2. After you start the IDE we click on the upper left “New…” button. In the projects window we select “Node.js project (server)”:
We close the dialog using the OK button and we have our own “Hello world” demo ready :).
In this demo, we create a new HTTP server, which listens on port 80. For each connection an anonymous method is run which only responds (by closing the response) with the famous (?) “hello world” text. Because node.js runs in a console, we can only show some debug text using “Console.log”.
Let’s run! Press F9 or the “Execute” button to run the server.
(note: when you get “ShellExecute failed with error code 2” you need to install node.js: http://nodejs.org/download/)
Now, start your browser and go to http://localhost:
:
Simple isn’t it? 🙂