
PurpleJS – An alternative to Node.js for Java projects - thousande
http://webagility.com/posts/purplejs-the-alternative-to-node.js-for-java-projects
======
thalesmello
I particularly don't find the problem it solves appealing. The power of Node
comes specifically from its everything async programming model, Javascript is
just a detail.

So what's the point in taking away the good part, and keep the cumbersome one?
If you just want to program a Synchronous server in the JVM,just stick to
Java.

~~~
cel1ne
I hope you don't mean the JVM by "the cumbersome part". It think is
unparalleled in performance, garbage-collection, general dev-ops and
monitoring capabilities.

You can run many different languages on it, all nicely contained within the
virtual machine.

As far as I know Twitter replaced their Ruby/Rails with Code on top of the JVM
for these reasons.

Also I don't think it's good to religiously stick to async/"just one thread"
and sync/"one thread for everything". The most performant answer depends on
the real world scenario and almost always lies somewhere in between.

~~~
my123
The JVM is nowhere near as flexible as the CLR.

~~~
peterashford
In what way?

~~~
my123
The CLR can be used to run C++ code compiled with the C++/CLI (/clr:pure)
setting of MSVC. Java apps can even run on the CLR because of IKVM
([https://www.nuget.org/packages/IKVM](https://www.nuget.org/packages/IKVM)).

Good luck at using pointers in Java.

------
smashed
How does this relate to Nashorn?

With something like Avatar-JS [1] you can even run some NodeJS apps without
modifications on the JVM.

[1] [https://avatar-js.java.net](https://avatar-js.java.net)

~~~
desdiv
It's built on top of Nashorn[1].

[1]
[https://github.com/purplejs/purplejs/search?utf8=%E2%9C%93&q...](https://github.com/purplejs/purplejs/search?utf8=%E2%9C%93&q=nashorn)

~~~
wentoodeep
Ok so no android. Next.

~~~
eropple
Why would you want to run this on Android? I'm not seeing the appeal.

------
iamleppert
Why do people think async code is complicated and keep trying to replace it?

I think there are just people who will never understand or fully grok the
beauty, power and simplicity of functional programming and will always seek to
replace it. I feel sorry for them.

~~~
skrebbel
> _Why do people think async code is complicated and keep trying to replace
> it?_

As usual, @munificentbob explains it best:
[http://journal.stuffwithstuff.com/2015/02/01/what-color-
is-y...](http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-
function/)

------
fredliu
Isn't use case proposed by PurpleJS covered by Vert.x already? Or am I missing
anything?

~~~
stenrs
Vert.x is similar. PurpleJS tries to make development of your webapps easier
by combining the require-js model and a "sinatra"-way of developing rest
endpoints.

------
dewiz
I wonder if LucasArts is happy with that logo :-) The image and the font
brought up some good memories.

[https://en.m.wikipedia.org/wiki/Day_of_the_Tentacle](https://en.m.wikipedia.org/wiki/Day_of_the_Tentacle)

[https://images-na.ssl-images-
amazon.com/images/I/514Q95XGV8L...](https://images-na.ssl-images-
amazon.com/images/I/514Q95XGV8L.jpg)

~~~
jsuperman
They have actually stated on Twitter that the mascot is inspired by the DOTT
character and the Java character (Duke):
[https://twitter.com/purple_js/status/732660360348631040](https://twitter.com/purple_js/status/732660360348631040)

------
agentgt
I have seen several similar things that essentially use existing Java
libraries or the libraries themselves offer it (Javascript).

* jooby [1]

* Vert.x [2]

* Rapidoid (I can't find the exact link where JS was used) [3]

I'm just not entirely sure why you would trade a language that is generally
much safer for one that is known to be problematic at scale particularly since
Java 8 has lambdas so you can do callback async style if you like. I mean I
suppose you could use typescript but at that point why not stick with Node and
if you need JVM stuff just make some sort of microservice to access it from
Node.

If it is a learning thing than (as Java is complicated) than Clojure is far
better option (I'm always amazed how easy it is to learn any Lisp as syntax
becomes a non issue).

[1]: [http://jooby.org/](http://jooby.org/)

[2]: [http://vertx.io/](http://vertx.io/)

[3]: [http://www.rapidoid.org/](http://www.rapidoid.org/)

------
diegorbaquero
Interesting offer, would be great to have some benchmarks comparison to see
the value of it. Do you happen to have some?

~~~
jsuperman
I haven't seen any benchmarks yet, but the framework is actually originally
the core engine of the web os / cms Enonic XP. Worth checking out:

[https://discuss.enonic.com/t/purplejs-an-alternative-to-
node...](https://discuss.enonic.com/t/purplejs-an-alternative-to-node-js-for-
java-projects/694)

[https://enonic.com/](https://enonic.com/)

------
tracker1
I'm just not sure I see the value... and in the end, not sure it will work out
any better than the DLR attempts with .Net... It's interesting, just not sure
I see the value. The Java runtime is about 60mb to download, then the extras
for this... vs Node's runtime download under 14mb with a similar amount of
library downloads for a given project.

That doesn't include the disconnect from the rest of the JS ecosystem which
has centered around npm at this point (at least for the package repository
itself, baring the yarn front end).

~~~
andrea_s
Perhaps that's closer to ClearScript
([https://clearscript.codeplex.com/](https://clearscript.codeplex.com/)) in
the .NET environment - although ClearScript has a broader area of application
and supports multiple engines.

------
cheriot
This could be pretty cool. So in theory, all the Java, Scala, etc servers out
there can wire up an isomorphic single page app without calling out to a Node
process.

Once the docs are written...
[https://github.com/purplejs/purplejs/wiki/Embedding](https://github.com/purplejs/purplejs/wiki/Embedding)

~~~
premium-concern
Or you use Scala and Scala.js and just get things done.

------
__derek__
This reminded me of Nodyn[1], a Node-compatible JVM implementation, which it
appears is no longer actively developed.

[1]:
[https://github.com/nodyn/nodyn#notice](https://github.com/nodyn/nodyn#notice)

~~~
stenrs
No, Nodyn tried to be fully compatible with NodeJs. PurpleJS is just an
alternative - the scope is not to be fully compatible. Also Nodyn has it's own
implementation of Javascript. PurpleJS uses Nashorn as the Javascript engine.

------
ilaksh
I didn't see any mention of Rhino. Does he know that existed (exists?)?

~~~
hibbelig
This uses Nashorn to execute the Javascript.

~~~
ilaksh
Oh ok so thats the new version then or rewrite? Just seems like he thinks its
a new thing even though its been around for many years.

~~~
BoorishBears
Rhino got a poorly documented rewrite and is a pain to use, JDK 8 forward
there's Nashorn. Elsewhere I've used J2V8, a very lightweight wrapper around
V8

------
gfosco
Why don't any of the examples use Java?... Even the examples on GitHub, none
of it looks any different than a Node.js project.

~~~
mgkimsal
Because it's still javascript, just running on JVM instead of... v8?

At least, that's my read of the project.

~~~
gfosco
Ok, that's part of it. This line from the page is what gets me, "create server
applications with Javascript but access and use Java libraries" and I think an
example of that is very important.

~~~
jsuperman
Actually, the best example of that is already mentioned in the article:

"With Enonic XP, the combination of Java and JavaScript is used to speed up
the development process and allow frontend developers to implement backend
services. I saw that this was a very popular approach to develop software more
effectively, and wanted everyone to be able to use the technology for free and
in existing investments. PurpleJS was born."

PurpleJS is the core of Enonic XP, made available separately as an open source
project (well, both are open source).

------
johnhenry
Is it correct to say that this is like JRuby, but with JavaScript in place of
Ruby?

~~~
PedroBatista
More like "This is like Sinatra running on the equivalent of JRuby"

------
lisivka
Does it use Rhino (to compile JS into bytecode)?

~~~
stenrs
No, it's using Nashorn which is bundled with Java 1.8+. It compiles Javascript
into JVM bytecode as Rhino, but it's more performant.

~~~
lisivka
Thanks. Last time I looked at JS in Sun Java, it was in interpreter mode only
due to license issues, so I always bundled Rhino with my projects to be able
to precompile JS code, so it will run faster. But now performance of Nashorn
is pretty impressive:
[https://blogs.oracle.com/nashorn/entry/nashorn_performance_w...](https://blogs.oracle.com/nashorn/entry/nashorn_performance_work_in_the)
.

------
kjsingh
simple question - can it work with npm dependencies out of box?

~~~
boggydepot
not out of the box, but the js vm used is based on webkit. for pure js deps,
it can probably use them.

but maven repo is what you have out of the box which contains all (mostly) the
libraries for java

