Home > Delphi, JavaScript, Object Pascal, OP4JS, Smart Mobile Studio > nodeJS, Smart Mobile and WinAPI services unleashed

nodeJS, Smart Mobile and WinAPI services unleashed

December 13, 2014 Leave a comment Go to comments

Oh man this has been quite the week, so much stuff to share that I hardly know where to begin! First of all, I have fallen absolutely in love with nodeJS. And when you see what this little puppy can do, I think you will too. Secondly, the tools I am working with now are so far beyond anything we have in the Delphi camp – that I cant wait to blow your mind utterly with what Smart Mobile Studio will be capable of.

First, services

nodeJS rocks!

nodeJS rocks!

As a die-hard Delphi programmer you have probably coded a few Win32/64 services in your day right? Delphi is an excellent tool for writing services – most of all because it allows you to fall back on the rich wealth of components the world of Delphi contains. Yet as you probably know, writing good services is a black-art. It’s time-consuming and very, very tedious.

Well hold on to your hat because with nodeJS you will be able to write fully operational windows services using nothing but nodeJS and Smart Mobile Studio (read: object pascal).

The magic is simply a matter of installing nodeJS (the standard installation). This gives you access to the command-line V8 executor, which you use to execute your smart pascal compiled JavaScript code. Why do that from shell you say? Well, because nodeJS is basically JavaScript outside the browser. Forget everything you know about JavaScript, the “DOM” and everything else. Strip the DOM from the language utterly – and what you are left with is a very flexible scripting engine.

Next, you install the magic package called “node-windows”, you install this with the npm package manager that comes with nodeJS (so it’s a normal shell command).

Once installed, you can start writing code which runs as a service. Yes you read right, you can now write fully fledged WinAPI services using Smart Mobile Studio and nodeJS.

This means that if you write a little REST or RPC server, which is trivial in the Smart Mobile Studio nodeJS project — you can have this puppy run side-by-side with all the other services. Let’s just clarify how awesome that is:

  • Smart Pascal code will run in the cloud with no dependencies
  • Smart Pascal code will run as a windows service

In other words, you can now write code which is designed to run anywhere — be it cloud based on locally on your physical server machine. Add the package “node-mysql” or “node-mssql” to the mix and you pretty much have everything you need to write the entire backend in Smart Pascal — and deploy locally first — only to deploy it without change to Azure or Amazon when the need to scale becomes real.

Here is the bootstrap JS code which installs your nodeJS compiled code as a Windows Service. Dont worry, we will wrap all of this in pascal syntax later on – so you dont have to mess with it.

var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'Hello World',
  description: 'The nodejs.org example web server.',
  script: 'C:\\path\\to\\helloworld.js'

// Listen for the "install" event, which indicates the
// process is available as a service.


I am so totally high on this right now, because I can now write code in 1 hour which would otherwise take me 2 days to complete in Delphi alone. Being able to write service applications, not to mention real executables with nodeWebkit, opens up a whole new world for Smart Mobile Studio.

But more importantly, it opens up a whole new world for object pascal programmers!

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: