r/node • u/TiZ_EX1 • Jun 30 '14
ELI5 how a Node.js/Node-webkit workflow actually works
Hi there. I am a traditional desktop developer with a scant amount of web development experience. I've created, packaged, and distributed desktop apps in programming languages like C#, Python, and Vala, using libraries like GTK+, Xfce4-panel, and python-twisted. I've been developing exclusively on Linux for several years, and I usually use waf to manage my projects.
I've become interested in node.js partly thanks to my other programming friends and partly thanks to projects like three.js, and cross-platform games being made with node-webkit. I feel like I'm maybe halfway decent at JS, but when it comes to learning about node.js and ways to use its modules for projects, I feel like I get subjected to a huge amount of culture shock, because it seems like JS development is way more jargonized than other languages, and works differently than other languages on a fundamental level.
I go reading about something, and it reads to me like "You can grunt your node.js with traceur in order to jasmine your underscore for your node-webkit!" which I know is complete nonsense, but that's what it feels like to me. Even though I kind of know what some of the individual stuff is, I have no idea how they fit together, and I suddenly feel like a developer worth no salt at all. :(
Here's what I do understand: Grunt is kind of like waf, maybe? It can be used to manage your project and automates tasks. It seems like compared to other languages, there are way more things in node.js (or heck, just JS in general) that do things to your code, like traceur and underscore, compared to libraries and APIs that are used by your code.
I have no idea how I would actually go about packaging and distributing something I make with node.js, and I have no idea how node-webkit relates to node.js in terms of how to actually use it for projects. And best practices are obviously right out.
I know that making this post means exposing myself for the programming scrub that I truly am, but I would like to learn, so please enlighten me, node gurus! Thank you.
11
u/silvinci Jul 01 '14
Long time node user here.
Grunt is a "task runner / automation tool". With Grunt you can define various tasks that can do things to your code or just start a dev server or actually deploy your code to production, etc...
However Grunt is mostly used for "building / compiling" your code. Many people use preprocessor languages like less for CSS or CoffeScript for their actual JS code. In order to use the this code it first has to be compiled to stuff the browser / node can run. Grunt can do this.
As always, there are competing task tunners / compilers / whatever, like Gulp or Broccoli. They all focus on different philosophies.
Jasmine is a fancy testing tool with a focus on BDD (Behaviour Driven Development). You could configure Grunt to run those Jasmine test.
Underscore is a utility library. It adds a lot of sugar to vanilla JS for working with data or improving functional programming.
Traceur is a compiler similiar to the CoffeScript compiler. Tracuer allows you to use the new EcmaScript 6 (what we will have in a few months) features in todays EcmaScript 5 (what node and V8 run on) by polyfilling and reorganizing your code. Traceur could also be called by Grunt and the alike.
node-webkit is a... well... framework, I guess?
You could say it's a heavily customized version of the node binary, that comes with an integrated Chromium browser. While in vanilla node you run a js file, you run a webpage in node-webkit that can load js files via <script> tags. Those <script> tags then have access to all the core node modules using the require("module"); function.
There is an alternative to node-webkit: atom-shell by GitHun. Basically it's just the same. There are just two main differences:
Personally I prefer atome-shell. They have some good docs and a well written quick start guide. They also explain how to distribute your app.
If you have any further questions, feel free to ask.
3
u/Calabri Jun 30 '14
I would recommend reading the stream-handbook.
And also the browserify-handbook.
I can see how node culture/jargon can be overwhelming, because there are so many ways to do the same thing. Packaging / distributing something is as easy as using git. The npm docs explain everything you need to know about that.
What separates Node from other languages I've used is the server api. Most other languages have a much greater separation of concerns between the server / backend. The server is usually a 'black box' (apache or otherwise) that you only configure. Node exposes a 'low level' set of building blocks that are expanded upon in the NPM ecosystem. And depending on what libraries you choose to install from NPM, your codebase can be very 'high level' or 'low level', organized / disorganized, imperative / functional / OOP.. whatever. And then you write code (with gulp/grunt) to organize /build the directory you're working on, while you're working on it. You can even write programs to build the code to write the code to build the code.. etc. etc. etc. And everything is async by default.
6
u/pappydigsgraves Jun 30 '14 edited Jun 30 '14
Hey, I'm a node.js dev and I don't even know what Grunt does beyond the basics, really, because I don't use it. There's a trend recently to automate the shit out of everything and then automate the automation, too. That's fine if you know what you're doing, but otherwise I subscribe to the school that it's better to start off doing things yourself manually so you understand them better.
First off, what do you plan to make with node.js? I'd recommend just installing node and playing around with it. In my opinion all you really need to learn is npm (an excellent package manager) and maybe a framework like Express if you're building a website or socket.io if you want to do realtime online games. If you're looking to write a non-browser standalone application then take a look at node-webkit.
2
u/robothor Jun 30 '14
Hmmm, there's a bit in here. Some of this is a little complex because Javascript is used in the browser and on the server via node. Some of the tooling exists because managing assets is fairly complex. Grunt and many of its plugins are an examples of this.
The pace of development in the node and javascript community is high and this can make it hard to follow the bleeding edge. But most of the tools have something similar in other languages: build tools, testing, code coverage, and so on.
In terms of packaging and distributing something the answer really depends on what you are doing. If you want a command-line tool, then maybe npm is fine. If you are building server software that you want installable then you might want to use npm or your distro's packaging system (e.g. Debian packages).
node-webkit is useful if you want a "double-click to run" package for Windows, Mac and Linux. It essentially bundles a node runtime in a format that is recompiled and set up for different platforms. But the packaging step should be the last part of your development process.
BTW, if you want a nice example of a node-based app, check out Tilemill. It was released before node-webkit but does something very similar and it is instructive to see how their app is structured.
Is there any place in particular that you are getting stuck?
2
u/OomplexBOompound Jul 01 '14
I found running through this program very helpful when starting with Node: https://github.com/rvagg/learnyounode
1
u/aredridel Jul 02 '14
You're not wrong. There's a lot of stuff -- a good portion with node specifically can be looked up on npm (use
npm searchor the site).gruntis a task runner -- vaguelywaf-like, but more like shell-scripts, kind-of.jasmineis a test suite tool.traceuris an ES6-to-ES5 compiler. Sounds like whatever you're working with has gone tool-crazy, with lots of pieces that may not be strictly necessary.Now, node-webkit relates to node interestingly, in that it really is binding the two together, and because it's for desktop apps, it's different than node on its own -- webkit's not just a thing you can load as a library and have it form a desktop app on a mac, so there's all this bundling and layout stuff to do.
That way it ends up making a custom node+webkit binary that runs your app.
Don't take best practices too hard without some context: One team's best practice is another's horrible mistake -- it depends on the problem being solved, not some generic concept of best.
Node is different than the unix land you've lived in, and some of these projects are of the high opinon, high convention cultures -- these are the ones that develop a lot of jargon.
Where to start? Learn the module system, well and thoroughly. Learn to identify modules that break it in some way -- they're the most problematic ones. Sometimes there's a reason (node-webkit is one of 'em!) and sometimes it's just a developer trying to port something from another language in a way that makes no sense.
1
u/goldglovecb Jul 10 '14
I've been using node for a very long time, and I recently released what's becoming a fairly successful open source node-webkit app called Fenix Web Server (http://fenixwebserver.com), for Windows and Mac (also runs on Linux but I don't support it). It might be a decent starting point just to get familiar with node-webkit.
While most of the points made are correct, there are a couple of things to keep in mind. Node-webkit is a specific version of node tied to chromium. I often hear "it's like Chrome with Node.js embedded", which is a good high level description, but not quite technically accurate. For example, you cannot use the Chrome notification API's because they are currently part of the browser, not webkit.
There are alternatives like Atom-shell, which is actually very much like brackets-shell from Adobe. Both are very much tailored to the editors they are building, whereas node-webkit is for more generalized applications. There are other alternatives and other considerations. I actually did a talk where this subject is covered, currently available at http://capitalfactory.lifesize.com/videos/video/530/. Beware, the camera just ran for the whole event... the actual talk starts about 30 minutes in and only lasts about an hour. I'm trying to acquire the footage so it can be edited down and put on the fenix YouTube channel.
I could go on and on, but I think the big take-away I can offer is to not think of node-webkit as node. They share a name and some cool features, but their use cases are quite different. Node-webkit is probably the most advanced of the embedded node-on-the-desktop options, but there are still a number of kinks to work out. They're all pretty young projects.
I hope that helps in some small way.
1
u/meowrawr Jul 07 '14
Coming from a mixed development background (some software/hardware/web), I definitely felt the same way with node.js. I never really thought about it that way but you definitely hit the nail on the head and honestly, I think its a bit silly as well with the heavy jargonization. I do really enjoy node because it can be quite powerful, however I probably dont utilize so many of those "cool" sounding packages as frameworks seem to change so often and I prefer to not be reliant on some soon to be deprecated setup. Prior to node I did a bit of ruby on rails (easy, but just not my type of language) and before that I was doing mostly obj c/c with kernel work (and many other languages prior).
My suggestion is to start from the ground up, learn the way you probably have done in the past, and skip all trendy framework stuff for now. Focus on learning the overall flow, structure, and async nature of node. JS itself has plenty of literature and its quite easy really.
1
u/ayamflow Jul 11 '14
I'll be interested as well to see the differences between a node-webkit & atom-shell project, in terms of structure & workflow
0
u/[deleted] Jun 30 '14
[deleted] — view deleted comment