NodeJS on iOS

763 views
Skip to first unread message

Nathan Rajlich

unread,
Apr 15, 2011, 12:00:39 PM4/15/11
to nod...@googlegroups.com
Hey guys, I just wanted to show some people about how I got NodeJS running on my jailbroken iPhone 4.
I put a quick blog article up: https://tootallnate.net/nodejs-on-ios
Cheers!

马涛

unread,
Apr 15, 2011, 12:11:11 PM4/15/11
to nod...@googlegroups.com
I like it

发自我的 iPhone
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.

AJ ONeal

unread,
Apr 15, 2011, 12:24:02 PM4/15/11
to nod...@googlegroups.com
Sweet!

I've been hoping for something like this.

I've been thinking for a long time that I'd like to have a local webserver than can access native APIs that the browser can't yet piping webapps through node.

AJ ONeal

--

rtweed

unread,
Apr 15, 2011, 12:42:42 PM4/15/11
to nodejs
Very cool! Keep us abreast of developments. Access to those native
APIs will be fantastic

Rob

Nathan Rajlich

unread,
Apr 15, 2011, 12:55:06 PM4/15/11
to nod...@googlegroups.com
Wow, AJ, what an awesome idea!

I'm seeming to be hitting a road block with getting anything event-based working as a node module. I'm thinking that anything requiring delegates required the process to be the "active" process, in order for it to receive events. I'm not sure a way around this at the moment, other than I'm thinking of getting the the events at a lower level, using the private APIs.

The only thing is I still haven't been able to figure out how to register a callback for these. Any ideas anybody:
It would be cool to hook into these events (should be able to sent and receive them o.O), but I'm just not sure of the code. Any C gurus know how to do this? Thanks!

Karl Tiedt

unread,
Apr 15, 2011, 12:59:29 PM4/15/11
to nod...@googlegroups.com
Did the old jailbreak backgrounder hack ever get ported to the newer
iOS for iPhone4? If so that might get you where you need to be...

-Karl Tiedt

Dav Glass

unread,
Apr 15, 2011, 1:08:57 PM4/15/11
to nod...@googlegroups.com
When I try to execute it, I get a Bus Error and node bails out.

--
Dav Glass
davg...@gmail.com
blog.davglass.com


+ Windows: n. - The most successful computer virus, ever. +
+ A computer without a Microsoft operating system is like a dog
    without bricks tied to its head +
+ A Microsoft Certified Systems Engineer is to computing what a
   McDonalds Certified Food Specialist is to fine cuisine  +

Nathan Rajlich

unread,
Apr 15, 2011, 1:11:04 PM4/15/11
to nod...@googlegroups.com, Dav Glass
What device and os version?

Nathan Rajlich

unread,
Apr 15, 2011, 1:43:38 PM4/15/11
to nod...@googlegroups.com
Ya, so I'm thinking 4.3 is required. It didn't work on the 3G I just tried running 3.1.2, it died with "Illegal instruction"...

Dean Mao

unread,
Apr 15, 2011, 5:06:23 PM4/15/11
to nod...@googlegroups.com, Nathan Rajlich
I'm assuming it probably requires something that Apple wouldn't allow for production apps right?  I thought in 4.3, Apple allowed js code to be run inside apps, but I'm not sure if nodejs counts.  It would be pretty cool if we could write parts of the app in nodejs with just a few bindings to the ObjC world.

Matt Patenaude

unread,
Apr 15, 2011, 5:15:40 PM4/15/11
to nod...@googlegroups.com, Nathan Rajlich
Right, this would not be allowed on the App Store. JavaScript (and potentially other scripting languages) execution is permitted, but only using the included Apple-provided interpreters, which have been sufficiently sandboxed.

Node.js could circumvent this sandbox, thereby allowing the potential (when combined with node-ffi[1], for instance) for arbitrary code execution from content downloaded from the Internet. This would not only open a number of potentially-sizable security holes, but it would enable apps to easily violate the App Store terms and conditions by introducing new functionality after the application has been installed.

-Matt

Ryan Dahl

unread,
Apr 15, 2011, 5:35:43 PM4/15/11
to nod...@googlegroups.com, Matt Patenaude, Nathan Rajlich
On Fri, Apr 15, 2011 at 2:15 PM, Matt Patenaude <ma...@mattpatenaude.com> wrote:
> Right, this would not be allowed on the App Store. JavaScript (and
> potentially other scripting languages) execution is permitted, but only
> using the included Apple-provided interpreters, which have been sufficiently
> sandboxed.
> Node.js could circumvent this sandbox, thereby allowing the potential (when
> combined with node-ffi[1], for instance) for arbitrary code execution from
> content downloaded from the Internet. This would not only open a number of
> potentially-sizable security holes, but it would enable apps to easily
> violate the App Store terms and conditions by introducing new functionality
> after the application has been installed.
> -Matt
> [1]: https://github.com/rbranson/node-ffi

Apple would not prohibit Node from running an app.
http://www.apple.com/pr/library/2010/09/09statement.html
http://daringfireball.net/2010/09/app_store_guidelines

However Nathan's hack is for a rooted phone - this is quite different
than running Node inside the CF event loop, which is a rather large
undertaking.

Nathan Rajlich

unread,
Apr 15, 2011, 5:55:52 PM4/15/11
to nod...@googlegroups.com
Indeed, getting node running inside a regular iPhone app is a whole other beast. Apps use their own event loop and so does node, so that gets tricky. This is, I believe, the reason why I haven't so far been able to get any delegation event callbacks working from within a node module, but I'm only speculating.

In any case, I'm still looking for another way of getting hardware events to node. I think the GSEvent stuff is where I should be looking, but I haven't found any example code or anything.

Other then Dav above, has anybody else been trying this .deb? Has it been working?

Morteza Milani

unread,
Apr 16, 2011, 3:36:16 AM4/16/11
to nod...@googlegroups.com
Wow, that's cool!

Can we do such a thing for Android phones or tablets? anyone did it before? I know that Android uses V8, so porting Nodejs to android should be easy I think.

Thank you for sharing this!

Dewey

unread,
Apr 16, 2011, 6:09:02 AM4/16/11
to nod...@googlegroups.com
I'm on iPhone 3GS / 4.3.2 and I've got it working, thanks for that.. I experienced a couple of issues:
- Had to install curl + git via Cydia to install NPM and node-iOS (couldn't find ios @ npm so had to clone it inside ~/node_modules)
- Got Error: ECONNREFUSED, Could not contact DNS servers while installing something with NPM, had to follow step 4 of https://github.com/joyent/node/wiki/Building-node.js-on-Cygwin-(Windows)

But the require('iOS').vibrate(); option works beautifully ;) Can't wait for other native options.

Nathan Rajlich

unread,
Apr 16, 2011, 1:01:26 PM4/16/11
to nod...@googlegroups.com
Thanks for that Dewey. Yes indeed, node-iOS is not currently on npm. I'm still trying to think of the best way to do it while still supplying a precompiled binary, so for now I would recommend just cloning the repo to ~/node_modules or otherwise. And the '/etc/resolv.conf' step was also necessary, thanks for pointing that out, as my iPhone didn't even come with an '/etc/resolv.conf' file at first!

jacter

unread,
Apr 16, 2011, 4:13:18 AM4/16/11
to nodejs
Hi Nathan,

Working with my ipad (iOS 3.2) jail break,but it is leaking.
Maybe NSAutoreleasePool is not implement complete?
And , I skip my uniqueIdentifier.


> iOS.device()
2011-04-16 16:01:28.415 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0b450 of class NSCFString autoreleased with no pool in place
- just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x3155c71d 0xde4770 0x147c98
0x9c009c)
2011-04-16 16:01:28.421 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0b860 of class NSCFData autoreleased with no pool in place -
just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x32b07f4d 0x32b07dd7
0x32b07db5 0xde4790 0x147c98 0x9c009c)
2011-04-16 16:01:28.427 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0c2c0 of class NSCFString autoreleased with no pool in place
- just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x3155c7b1 0xde4834 0x147c98
0x9c009c)
2011-04-16 16:01:28.429 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0b890 of class NSCFData autoreleased with no pool in place -
just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x32b07f4d 0x32b07dd7
0x32b07db5 0xde4854 0x147c98 0x9c009c)
2011-04-16 16:01:28.434 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0c350 of class NSCFString autoreleased with no pool in place
- just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x316c20e1 0xde48f8 0x147c98
0x9c009c)
2011-04-16 16:01:28.436 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0b670 of class NSCFData autoreleased with no pool in place -
just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x32b07f4d 0x32b07dd7
0x32b07db5 0xde4918 0x147c98 0x9c009c)
2011-04-16 16:01:28.442 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0bf50 of class NSCFString autoreleased with no pool in place
- just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x316c2121 0xde49bc 0x147c98
0x9c009c)
2011-04-16 16:01:28.444 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0c220 of class NSCFData autoreleased with no pool in place -
just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x32b07f4d 0x32b07dd7
0x32b07db5 0xde49dc 0x147c98 0x9c009c)
2011-04-16 16:01:28.450 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0b8f0 of class NSCFString autoreleased with no pool in place
- just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x316c20b1 0xde4a80 0x147c98
0x9c009c)
2011-04-16 16:01:28.452 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0c0a0 of class NSCFData autoreleased with no pool in place -
just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x32b07f4d 0x32b07dd7
0x32b07db5 0xde4aa0 0x147c98 0x9c009c)
2011-04-16 16:01:28.457 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0c660 of class NSCFString autoreleased with no pool in place
- just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x316c2089 0xde4b44 0x147c98
0x9c009c)
2011-04-16 16:01:28.459 node[7026:903] *** _NSAutoreleaseNoPool():
Object 0xa0c260 of class NSCFData autoreleased with no pool in place -
just leaking
Stack: (0x32b35e5b 0x32b07d49 0x32b07d1b 0x32b07f4d 0x32b07dd7
0x32b07db5 0xde4b64 0x147c98 0x9c009c)
{ model: 'iPad',
localizedModel: 'iPad',
name: 'jacter’s iPad',
systemName: 'iPhone OS',
systemVersion: '3.2',
uniqueIdentifier: '' }

On 4月16日, 上午5時55分, Nathan Rajlich <nat...@tootallnate.net> wrote:
> Indeed, getting node running *inside* a regular iPhone app is a whole other
> beast. Apps use their own event loop and so does node, so that gets tricky.
> This is, I believe, the reason why I haven't so far been able to get any
> delegation event callbacks working from within a node module, but I'm only
> speculating.
>
> In any case, I'm still looking for another way of getting hardware events to
> node. I think the GSEvent stuff is where I should be looking, but I haven't
> found any example code or anything.
>
> Other then Dav above, has anybody else been trying this .deb? Has it been
> working?
>
> On Fri, Apr 15, 2011 at 2:35 PM, Ryan Dahl <r...@tinyclouds.org> wrote:
> > On Fri, Apr 15, 2011 at 2:15 PM, Matt Patenaude <m...@mattpatenaude.com>

Nathan Rajlich

unread,
Apr 16, 2011, 2:11:29 PM4/16/11
to nod...@googlegroups.com
Jacter, try extracting this prebuilt version of "node-autoreleasepool" for iOS ARM devices into the "node_modules" folder of "node-iOS", and make sure you're requiring the 'index.js' file of 'node-iOS', since it automatically includes autoreleasepool, nothing else should be needed on the developer's part other than to "require('iOS')". Here's the link:

Tom Fairfield

unread,
Apr 15, 2011, 8:20:52 PM4/15/11
to nod...@googlegroups.com
Is the patch you used to compile v8 in the git repo?

Nathan Rajlich

unread,
Apr 19, 2011, 5:01:53 PM4/19/11
to nod...@googlegroups.com
For the people trying to compile this themselves, I've updated my "iphone-build" branch to be current with node v0.4.6, and has all the necessary patches to build on a jailbroken iDevice with the GCC toolchain set up (though getting the toolchain set up is really a PITA):


I'll be releasing a node v0.4.6 darwin-arm .deb file shortly.

Tom Robinson

unread,
Apr 19, 2011, 7:11:26 PM4/19/11
to nod...@googlegroups.com, Matt Patenaude, Nathan Rajlich
On Fri, Apr 15, 2011 at 2:35 PM, Ryan Dahl <r...@tinyclouds.org> wrote:

You may also run into problems with V8's JIT not being able to
function properly due to iOS not allowing memory pages to be marked as
executable. This is supposedly the reason Nitro / SquirrelFish Extreme
isn't enabled in WebKit embedded in third-party applications.

http://daringfireball.net/2011/03/nitro_ios_43

Nathan Rajlich

unread,
Apr 19, 2011, 7:36:17 PM4/19/11
to nod...@googlegroups.com
Tom, this won't be a problem for this port, as it is intended for jailbroken devices only. In fact, I've now learned that the .deb I've already released works on iOS versions as low as 3.2, so running this node will have full JIT capabilities. Jailbreaking enables executable memory pages in most cases...

Tom Robinson

unread,
Apr 19, 2011, 7:47:20 PM4/19/11
to nod...@googlegroups.com
Understood, I was adding to Matt and Ryan's comments about running
Node in an iOS app distributed on the App Store. Just wanted to make
sure no one sunk too much time into integrating Node with the CF run
loop before discovering this.

Nathan Rajlich

unread,
Apr 24, 2011, 4:02:53 PM4/24/11
to nod...@googlegroups.com
Finally found the time to make some '.deb's for node v0.4.6 and v0.4.7, so download them if you care to:

Nathan Rajlich

unread,
May 21, 2011, 10:55:19 PM5/21/11
to nod...@googlegroups.com
I just got node v0.4.8 packaged up as a .deb for your easy installation pleasure:

Enjoy!

heydenberk

unread,
Jul 8, 2011, 6:12:37 PM7/8/11
to nodejs
Hey!

I'm part of a team that has done some work on incorporating node.js
into iOS applications. Are there plans to officially support iOS (or,
for that matter, Android) in the near- or medium-term? Has node.js
been run on a non-jailbroken phone, and is there a definitive answer
as to whether it'd be allowed into the iOS App Store?

Thanks!

On May 21, 10:55 pm, Nathan Rajlich <nat...@tootallnate.net> wrote:
> I just got node v0.4.8 packaged up as a .deb for your easy installation
> pleasure:https://github.com/downloads/TooTallNate/node/node-v0.4.8-darwin-arm-...
>
> Enjoy!
>
> On Sun, Apr 24, 2011 at 1:02 PM, Nathan Rajlich <nat...@tootallnate.net>wrote:
>
>
>
>
>
>
>
> > Finally found the time to make some '.deb's for node v0.4.6 and v0.4.7, so
> > download them if you care to:
> >https://github.com/TooTallNate/node/downloads
>
> > On Tue, Apr 19, 2011 at 4:47 PM, Tom Robinson <tlrobin...@gmail.com>wrote:
>
> >> Understood, I was adding to Matt and Ryan's comments about running
> >> Node in an iOS app distributed on the App Store. Just wanted to make
> >> sure no one sunk too much time into integrating Node with the CF run
> >> loop before discovering this.
>
> >> On Tue, Apr 19, 2011 at 4:36 PM, Nathan Rajlich <nat...@tootallnate.net>
> >> wrote:
> >> > Tom, this won't be a problem for this port, as it is intended for
> >> jailbroken
> >> > devices only. In fact, I've now learned that the .deb I've already
> >> released
> >> > works on iOS versions as low as 3.2, so running this node will have full
> >> JIT
> >> > capabilities. Jailbreaking enables executable memory pages in most
> >> cases...
>
> >> > On Tue, Apr 19, 2011 at 4:11 PM, Tom Robinson <tlrobin...@gmail.com>
> >> wrote:
>
> >> >> On Fri, Apr 15, 2011 at 2:35 PM, Ryan Dahl <r...@tinyclouds.org> wrote:
> >> >> > On Fri, Apr 15, 2011 at 2:15 PM, Matt Patenaude <
> >> m...@mattpatenaude.com>

Tim Caswell

unread,
Jul 8, 2011, 7:20:10 PM7/8/11
to nod...@googlegroups.com
On Fri, Jul 8, 2011 at 3:12 PM, heydenberk <heyde...@gmail.com> wrote:
> Has node.js been run on a non-jailbroken phone?

I don't know about iOS or Android, but it (node) is part of the
official SDK on webOS. ;)

Stephen Belanger

unread,
Jul 8, 2011, 7:22:46 PM7/8/11
to nod...@googlegroups.com
No shameless self-promotion there at all. ;)


You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at

Tim Caswell

unread,
Jul 8, 2011, 7:26:07 PM7/8/11
to nod...@googlegroups.com
Just saying ;)

Anyway, I think it's cool and fun to try to get node on non-supported
platforms as well, good luck.

Mark Hahn

unread,
Jul 8, 2011, 7:28:41 PM7/8/11
to nod...@googlegroups.com
I don't see a problem with self-promotion if it contributes to the
discussion, which this did. It would be nice though if the author
acknowledged any connection with whatever is promoted.

On Fri, Jul 8, 2011 at 4:22 PM, Stephen Belanger <cyruz...@gmail.com> wrote:

Tim Caswell

unread,
Jul 8, 2011, 7:31:33 PM7/8/11
to nod...@googlegroups.com
To be fair, webOS was using node before I became an employee and I
thought it was cool then too, so I'm not promoting it just because I
work on it.
So disclosure, I now work on node on webOS as my day job.

Stephen Belanger

unread,
Jul 8, 2011, 7:35:12 PM7/8/11
to nod...@googlegroups.com
Wasn't criticizing. Just teasing. As a non-webOS employee I would agree that it is pretty cool. :)

Mark Hahn

unread,
Jul 8, 2011, 7:35:42 PM7/8/11
to nod...@googlegroups.com
Disclaimers about connections don't really speak to motive. A
reporter says when they or the news organization has a connection to a
story, and one assumes their motives are pure.

Nathan Rajlich

unread,
Jul 8, 2011, 8:15:28 PM7/8/11
to nod...@googlegroups.com
In any case, I think the answer is still "no", heydenberk.

I haven't heard of anybody getting V8 running on a non-jailbroken
device, and I'm almost positive that it's not currently possible
thanks to Apple.

You can follow the V8 ticket I made regarding the issue, which has
surprisingly gotten a bit of attention lately, including a new patch
that I haven't even tried yet:
http://code.google.com/p/v8/issues/detail?id=1312

Reply all
Reply to author
Forward
0 new messages