Jacob Lowe

Native NodeJS Apps

by Jacob Lowe on

This was my first talk at JSLA. At the time I had given talks quite a bit a meetup called Riverside.JS. I love looking back on this talk because it was just at the time when electron was split into its own project. I do not even think that I name electron at all because at the time it was called atom-shell.

Native NodeJS apps are a relatively new breed of apps coming out of the NodeJS community that combine NodeJS and Webkit. Ill be going over

  • what are the options out there
  • what kind of things can these apps do compared to webapps
  • what are the current pro/cons of making a NodeJS native

Native NodeJS apps are a relatively new breed of apps coming out of the NodeJS community that combine NodeJS and Webkit.

Transcripts (auto-generate)

  • so how's everybody doing
  • um my name is jacob and i'm going to be
  • talking about native node.js apps
  • i'm on github it's my username for
  • github i'm going to have i have some
  • relevant material up there so if you
  • want to go check that out um all my
  • demos will be up there as well
  • i work full time at a company called
  • honey inc we make embeddable
  • quizzes and and ads and stuff it's
  • really cool um we're looking uh we have
  • some job openings up on our website um
  • if you're interested come talk to me
  • afterwards and then i'm also an
  • ambassador for syngrid
  • so you might be thinking like what is a
  • native node.js app
  • you can almost say like isn't all
  • node.js apps native because you can
  • essentially run c code from them so
  • i don't know how much more native you
  • can get
  • well yeah they are they are native
  • node.js apps but i'm i was trying to
  • think like what
  • should i call these type of apps because
  • there's not really like a a
  • qualification or like a marketing term
  • for these type of apps so like it's not
  • a web app at all because it does so much
  • more than a web app it would be kind of
  • degrading to it to say hey it's a web
  • app
  • a native web app is actually a little
  • bit better but it's it's not a web app
  • at all because a kind of a web app like
  • implies that it can be ran on a browser
  • which if you run a heavily modified
  • browser you can run these apps but not
  • really on a regular web browser
  • node.js app it is kind of a node.js app
  • but like when you say node.js app
  • you're usually talking about something
  • like a web server or some type of
  • networking server or even though it can
  • be a number of things and then like
  • native node.js app is kind of lame as
  • well i mean i don't like it i think we
  • could do a little bit better
  • so like super effing cool way to use
  • webtech to make a native-esque type of
  • app
  • i like that a lot better
  • so but really what i'm talking about is
  • a lightweight version of a browser
  • and then the runtime of the browser is
  • replaced with node.js runtime which is
  • really cool and i say most instances
  • because there's a lot of choices
  • um well not a lot of choices but there's
  • multiple choices to this
  • and and luckily they're open source as
  • well
  • so
  • the first one i'm going to talk about is
  • desk shell now desk shell
  • has been around for a while
  • it's
  • not that actually actively developed but
  • it is very close to a web app you
  • essentially are running a web app that
  • interacts with the backend
  • and they're kind of they're it used to
  • be called app.js and i think they
  • changed the name because they're looking
  • to support php i don't know if that's
  • considered like a bad thing about this
  • type of app but
  • um and then the big guy that i think
  • most of you have probably heard about is
  • a node webkit it's very full featured
  • i've built apps in node webkit it is
  • very cool they even have a grunt plugin
  • to pack applications which is just
  • awesome
  • like you have no idea
  • it is kind of slow to start up
  • and there's a number of reasons for that
  • and actually i was going to talk about
  • node webkit throughout this whole entire
  • presentation
  • um but then something happened uh this
  • month and just for reference for people
  • who are watching this online this is may
  • of 2014
  • so what happened is that
  • github
  • released their atom ide to open source
  • which i thought was great i mean a new
  • project that's open source it's using
  • very similar technologies i've actually
  • speculated with a lot of my friends that
  • they're using node webkit
  • in atom to build this ide
  • but they actually hired on one of the
  • core developers of node webkit to build
  • adam shell
  • which is very actively developed because
  • it's
  • from github and it acts just like
  • node.js runtime
  • it is missing a few key features because
  • really it was just built to run their
  • ide and now they're just open sourcing
  • it so eventually they'll get these
  • features like uh for instance you can't
  • even set like an icon to the app very
  • easily grant you can do it but you have
  • to kind of hack around to do it compared
  • to like what you can do in node webkit
  • so before i talk about like
  • how cool these things are these types of
  • apps there is some things to think about
  • before you like try to build a
  • production app with one of these
  • so it's different i mean this is with
  • all new technology it's going to be
  • different um for instance like things
  • like live reload will not work right off
  • the bat with it maybe actually this
  • stuff's being actively developed pretty
  • quick so there actually might be a
  • plug-in for live reload now
  • but at the time of making this there
  • wasn't
  • and like
  • it's it's just weird and like for
  • instance have you ever made a web app
  • that you've never had that you don't
  • have access to the window object like
  • you always have access to that where you
  • can like just store stuff in there and
  • you can just pull stuff right back out
  • these types of apps you don't have that
  • capability
  • sometimes you have it'll
  • access window a lot of times though
  • and then like there's something that we
  • don't have to deal with as web
  • programmers that you have to deal with
  • with these type of apps which is like
  • uses on different os's usually these
  • browsers just work on these different
  • os's and you have to worry about you
  • know the actual processes and stuff
  • but um
  • you have the same
  • browser but now you you're storing data
  • into different locations i actually have
  • an app that i built that like
  • i had a friend on a mac computer that
  • couldn't run it just for some stupid
  • reason
  • um but yeah that's one thing to look out
  • for
  • um and then actually uh the app store
  • like a lot of people are trying to like
  • release these apps the app store i've
  • heard a lot of nightmare situations
  • where they didn't uh pass
  • uh the app store and then i've actually
  • heard of a few node webkit ones that
  • have
  • but um adam shell i guess there's people
  • trying to do it but a few of the github
  • employees don't think that they're gonna
  • pass
  • and then it's experimental like some of
  • the features that you've used on web and
  • that you've come to love or on node.js
  • some of those features just don't work
  • like
  • granted you can get native plugins to
  • work npm modules that run c code but
  • like there is catches for instance like
  • adam shell
  • is only running version 0
  • 0 11 9 is the first version that it came
  • out with so if you have a native plugin
  • that's running at 0 10
  • only is compatible with 0 10 versions of
  • node
  • you're going to run into a lot of issues
  • because they did a lot of changes with
  • native bindings
  • but there is before i blame you guys out
  • there is a lot of exciting stuff about
  • this app about these types of apps and
  • one thing that really excites me is that
  • like w3 standards they have a bunch of
  • different specs that come out all the
  • time that like are just like
  • experimental sometimes or sometimes you
  • know have been around for a while but
  • actually these features can be built by
  • just your regular
  • javascript programmer so they can start
  • playing with these types of things right
  • away and actually what's cool is that
  • you can actually learn these
  • technologies before they even come out
  • in browsers so when they do come out
  • it's not something new to you
  • and then you actually have control over
  • the browser as a web programmer there's
  • always been that moment where you just
  • like curse ie8 you know to all hell
  • where like something's broken you don't
  • know why you actually control
  • the the browser that you're running on
  • which is great which means you can run
  • you know all the cool apis that that
  • browser gives you
  • um
  • it's it isn't just a node.js app it does
  • so much more like it has a gui that
  • isn't a terminal i mean i don't know how
  • many times you know
  • a client has asked you for a terminal
  • program that they can play around with
  • because it doesn't happen because
  • clients usually want something that's
  • nice and pretty and something that has
  • an actual gui not just a terminal
  • program
  • it this is for people who like
  • hate saying setting up dbs or they just
  • don't want to do it
  • it actually has built-in web storage so
  • if you wanted to actually get up and
  • started without having to set up
  • something like leveldb or our uh
  • mysql or sqlite or something some
  • embeddable database it actually already
  • has indexeddb and local storage and all
  • that kind of cool stuff in it so you can
  • get started really quick
  • and it has a real dom i don't know how
  • important this is to you but
  • you can actually interact with this dom
  • and see things happening where like if
  • you use js dom and stuff it feels kind
  • of abstract
  • you're interacting with it but it's it's
  • kind of you know something that is um
  • very abstract
  • and then you have access to native
  • features and i'm talking about like
  • native gui features like menus menu bars
  • windows docs start menu and actually i
  • have a demo here of a
  • node webkit app
  • um and this is a note-taking app that
  • syncs up with gist and actually you have
  • access to
  • as you can see here i have you know
  • access to the file menu
  • when i like try to switch apps you see
  • that it's in here
  • let me close that
  • so you actually have access to those
  • types of things which is great because
  • like you i granted you could probably do
  • that with a regular node.js app but you
  • have to hack around to get to it and
  • then it's like kind of awkward without a
  • window to actually show a gui in
  • so all those things were about like node
  • uh like web apps like what abs what uh
  • what web apps do compared to node.js
  • apps so i want to explain why it's not
  • just a web app
  • so you have access to node.js apis like
  • streams file system child processes all
  • kinds of really cool stuff built in and
  • i'm not talking about like file access
  • like you would have in chrome or file
  • access that you would have like through
  • browserify or something you actually
  • have access to the whole file system
  • which is great we'll grant it you have
  • the permissions
  • um and then synchronous module imports
  • these are really great where you just
  • like
  • require something and it's there
  • where like i i can hear you saying like
  • oh whatever you know you can you you can
  • actually do this stuff with component i
  • o or or browserify so why is that
  • important
  • but actually you have like access to
  • like all the npm modules on npm granted
  • there are some um some gotchas where
  • like with native modules and stuff like
  • that where
  • they kind of don't work um sometimes but
  • a lot of the modules will work right out
  • of the box
  • and one thing that's really cool is that
  • you can actually interact with installed
  • programs like git python or like your
  • keychain or something and actually i
  • have another demo showing this
  • so i'm going to go to my terminal
  • switch over
  • and i'm going to go
  • so i'm going to start up the app this is
  • actually an adam shell app
  • as you can see it's showing me like a to
  • do of like a a to do md
  • and actually i'll go into my editor
  • and i'll open up this one let me bring
  • that back
  • so
  • um
  • let's say i want to
  • check off like we went to the the kitty
  • bar afterwards
  • so i save that and then you'll see
  • that it should update
  • so it updated so i'm actually
  • interacting with git here
  • i'm actually
  • just running a
  • um
  • a child process to
  • run git right here so i spawn a get
  • process and then i just spit that the
  • output straight to the the uh
  • the window
  • which is really cool because i didn't
  • have to set up web sockets or or
  • anything crazy to get that running i
  • just it was it felt kind of natural
  • those things just interacting with each
  • other
  • and then also another really cool thing
  • is that i have access to hardware now i
  • have another demo here
  • and i'm not a hardware guy so
  • it's just a little bit of a warning so i
  • have this arduino board hooked up to a
  • like a breadboard with an accelerometer
  • on here
  • and then i have a demo app
  • that i'm going to run and is anybody
  • epileptic because i'm going to change
  • the background color of this thing
  • pretty quickly
  • yeah
  • oh actually real quick it's going to
  • throw an air
  • and that is because
  • i need to be sudo to get access to the
  • usb port
  • okay
  • so give it a second it's going to start
  • turning colors
  • so actually the wiring is probably off
  • on here because i'm not a uh
  • a uh
  • hardware guy but i can actually move
  • this thing around and it will change
  • colors and sometimes you'll get some
  • pretty colors out of it
  • but
  • yeah so i'm actually talking directly to
  • the app from this piece of hardware
  • which i mean i don't know of any web
  • apps that can really do that and i'm
  • using uh johnny five and
  • some hackery to to get this thing
  • working on adam's shell it's kind of a
  • pain to get that kind of stuff working
  • but yeah
  • my name is jacob and thanks
  • um so you can't run these things on
  • mobile phones right now just because you
  • would have to install like an apk or
  • an actual like ios app and these things
  • are mainly for desktop currently so but
  • you can have access to the camera of the
  • computer
  • but again you can do that kind of stuff
  • with web apps as well with get user
  • media and stuff like that
  • so if you were starting a new project
  • would you use node webkit or or adam
  • michelle
  • okay so
  • i should have said this before but the
  • main difference between adam's shell and
  • node webkit is that
  • node webkit your entry point is like an
  • html file so you essentially you render
  • that html file and then you start
  • running the scripts on that html page
  • and that's how you start up a node
  • webkit app
  • and with adam's shell it's different
  • because you have an entry point of a
  • js file so you actually start running
  • the js process and then you can open up
  • windows when your app's ready which is
  • kind of good with like
  • perceived uh performance like oh it's
  • opening up real fast but really you're
  • just waiting before and then opening up
  • the app
  • i would have to say
  • i would probably use adam's shell
  • well
  • it depends because if i
  • if the the timeline was like a month
  • probably node webkit because i need a
  • lot of the features that node webkit has
  • but if let's say it's like six months
  • adam shell probably will catch up in
  • terms of like the nice features like
  • icons and stuff like that in six months
  • so i would probably for a longer project
  • picked adam shell
  • it's written in coffee script oh yeah
  • that is the down part but
  • luckily you can interact with it with
  • javascript
  • okay um i think this is probably not a
  • fair question for you but i've been
  • using atom editor and
  • ui wise visual
  • it's awesome i love it but performance
  • wise
  • it's really sluggish
  • yes
  • you can speak on that at all so you is
  • you're essentially you're not completely
  • native you're still running a web
  • browser you're dealing with all the the
  • rendering of a web browser i mean it's
  • the same performance issues that you
  • would run into with a regular web
  • browser
  • right now it's not completely optimized
  • and i don't think there's you know
  • there's stuff that they can do
  • eventually to to optimize that but i
  • yeah i don't know i guess i'm just like
  • it's almost a proxy question for you i
  • want to ask when i said get up but like
  • are they aware of it
  • yeah they are aware of it actually i i
  • saw recently they pushed a big update
  • for scrolling speeds that's supposed to
  • improve the scrolling speeds actually i
  • have a linux box so i haven't really had
  • the the
  • the royalties of getting to use atom uh
  • the the actual ide
  • until recently so
  • yeah i don't
  • yeah i think they're they're doing stuff
  • to make the performance a little bit
  • better but it's still not completely
  • native
  • can we see the code for the hardware
  • yeah
  • so in the hardware
  • i just require the app here let me blow
  • this up
  • a little bit
  • so i require the app and then with adam
  • they have like this browser window and
  • then this is johnny five it's just a
  • module that i had to install
  • and then i just make a new board
  • when the board's ready i
  • make an accelerometer which is
  • talking to this thing and then when the
  • accelerometer inputs change i emitted
  • event
  • and let's see if we scroll over
  • accelerometer change and that just sends
  • out the data to that event
  • and here i'm just opening up the window
  • when the app is ready
  • and then actually the html file
  • so you have to do like background
  • require remote and then as you see from
  • the background i can require the app
  • and then in here
  • see this is converting it all
  • and right here i listen to the change
  • event so i grab the app and i look for
  • that excel change and then i handle the
  • change which then does some conversion
  • stuff to make it a little bit more like
  • rgb
  • than it comes out as
  • right here so
  • i guess given some of the like cross
  • uh cross os compatibility issues like
  • when
  • what would be the primary use case for
  • this like when would you say yeah we'll
  • do
  • we'll use uh node webkit rather than
  • just we'll build a node app and we'll
  • tell people to run it in webkit
  • um so
  • i think the main use case is when you
  • need something that's um
  • you want to build like a node app that
  • that has some good performance and you
  • want to write node code but you also
  • want access to some modules that you can
  • then like pull out bluetooth or some
  • technology that's just not quite there
  • plus like
  • for instance i i reference the the
  • service worker api or spec that's coming
  • out um
  • and like there's gonna they're gonna do
  • a lot of like network proxy next network
  • proxy and stuff with that to make like
  • caching really good in a browser but
  • with like this type of stuff you can
  • already do like those types of things to
  • where you can have really good caching
  • and really good you know uh access
  • really good like um
  • access to cash assets and stuff
  • so i would say like if you're doing
  • something with hardware it's a definite
  • go because
  • i don't know when you're ever going to
  • be able to like connect up a usb to
  • arduino board and then run like a web
  • app
  • um
  • but besides that there's there is i mean
  • there's a lot of cool things about it
  • but really uh
  • there's not too many differences from
  • the web platform which is kind of nice
  • in itself because then you can you know
  • have very similar code bases if you
  • wanted to make a web app in one of these
  • kind of like native esk apps
  • uh give it up for jacob
  • you