nodeJS, Smart Mobile and WinAPI services unleashed
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
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. svc.on('install',function(){ svc.start(); }); svc.install();
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!
Recent
The vatican vault
- January 2022
- October 2021
- March 2021
- November 2020
- September 2020
- July 2020
- June 2020
- April 2020
- March 2020
- February 2020
- January 2020
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- February 2013
- August 2012
- June 2012
- May 2012
- April 2012
You must be logged in to post a comment.