Thursday, October 9, 2014

Desktop applications with nodejs! ...as if winforms and wpf aren't dead already!


I used to disfavor javascript over other languages because it wasn't type-safe, it was hard to refactor, hard to write tests, find usages in the code, ...and the list goes on...
The past few years though, some amazing things have happened in the world that now make javascript an amazing language!

IDE's got much better! My personal favorite is WebStorm which has great auto-completion in javascript and supports many frameworks like nodejs and angular.

Web frameworks got much better! Newer and more advanced frameworks like angularJS and Ember allow you to write really organized and well structured javascript on the client side.

V8 was created and open sourced, which brought a whole variety of new tools to the table. Some of them being headless browsers like phantomJS which are great for automation testing, and creating quick web crawling scripts.

And my personal favorite - NodeJS! This tool is amazing! It can do so many things from being a fully functional and scalable backend server to a framework for writing desktop applications.


While looking into the code of PopcornTime I realized it was written in nodejs, with a framework called node-webkit. This was an amazing concept to me. It's basically a wrapper, that displays a frame with a website in it. The 'website' displayed is your typical client side code - html, javascript and css, so obviously you can use any framework you like, like angular or ember. This 'website' which is displayed in the frame can use all nodejs modules (directly in the js code) which gives you access to the operating system - you can access the file system, databases, networks and everything else you might need. Since nodejs runs on all major operating systems, you can also 'compile' your desktop app to run on any platform.
You can wrap all this as an executable file ('.exe' in windows) and easily tweak it not to show the toolbar which means the user has no way of knowing it's actually a website 'beneath' the desktop application they're using.


The steps taken to create a simple desktop application with node-webkit are super-simple!
(and easier than building a desktop application with any other language i've tried!)

First, I'm assuming you have nodejs and npm installed.
Now, download node-webkit : https://github.com/rogerwang/node-webkit#downloads

Start building your application just like you would a website. You can use the browser just like you're used to, to see your work.
When you want to start accessing node modules, you'll need to start running it with node-webkit.
In order to do this, just run the node-webkit executable from the command line with your main html file as a parameter.

C:\Utilities\node-webkit\nw.exe index.html


This will open your website as a desktop application.

You can now access all nodejs modules directly from the DOM!
Some of the operating system's api's are wrapped as node modules as well, so you can create a tray icon, native window menus, and much much more..

Debugging the app is also super simple and can easily be done with the Developer Tools, just like you would in Chrome! (you just need to configure your app to open with the toolbar visible, which you can define while developing in your package.json file)


I see so many benefits creating desktop applications like this, so I'm expecting to see many more apps running on this framework (or other nodejs-based frameworks) in the near future. (Except for major algorithms which probably would be better off written in C/C++. Hence, i'm not expecting to see the next Photoshop version be written in nodejs, but there are a ton of good examples out there which should be!)


Some good references :
- Node-Webkit Github page
- Introduction to HTML5 Desktop apps with node-webkit (a great tutorial to get started)

12 comments:

  1. I tried to master the Java script, but this is beyond my strength) Besides, my brother found talented developers http://www.nixsolutions.com/services/custom-software-development/ . For a small fee, they create projects and applications. For big business or family business, this is the best way to develop software. I experienced this on myself and now I work only with developers.

    ReplyDelete
  2. Wonderful article. Very interesting to read this article. I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.
    Data Science
    Selenium
    ETL Testing
    AWS
    Python Online Classes

    ReplyDelete
  3. Thanks mate. I am really impressed with your writing talents and also with the layout on your weblog. Appreciate, Is this a paid subject matter or did you customize it yourself? Either way keep up the nice quality writing, it is rare to peer a nice weblog like this one nowadays. Thank you, check also event marketing and finance events

    ReplyDelete
  4. These records characterize the actual server, just as assets and administrations that it gives. One of the administrations gave inside the application server is the administrator administration.https://www.blackmartappdownloads.com/

    ReplyDelete
  5. https://hostinglelo.in Since the internet has become more powerful in terms of providing a broad array of options and opportunities for people young and old, it has also become a great platform for games. The internet has definitely shaped today's concept of gaming. Gone are the days when board games rule the gaming arena, for the internet has added a new dimension to the idea of game. There are many games that can be found on the internet, and the most popular games nowadays are the War Strategy Games that have captured the attention of the young and the old.

    ReplyDelete
  6. https://www.buyyoutubesubscribers.in/2021/11/20/how-to-earn-money-from-youtube-views/ A lot of people use video responses in YouTube to bring extra traffic to their own videos and consequently boost the traffic which comes back to their websites. This article will explain what a video response is and how to make a video response in YouTube.

    ReplyDelete
  7. https://www.visualaidscentre.com/lasik-eye-surgery-in-delhi/ Businesses worldwide are quickly learning the value of using YouTube videos. Not only do videos entertain, they inform and put a company's brand name out there for all to see. Businesses create videos in order to drive traffic to their website or blog. Promoting these videos is an essential part of the marketing strategy.

    ReplyDelete
  8. Do you want a larger penis? In a unmarried massive survey a few years inside the beyond, about 45% of men said they did. And you should buy lots of over-the-counter and even scientific remedies that promise a larger penis. However do any of them simply work? Right here's facts about the 성기확대, extra information examine straight away to apprehend.

    ReplyDelete