Alternative Drupal Implementation in Node.js or other languages?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
thomas4019's picture

Has anyone thought about or done any work on doing an implementation of Drupal in a different language? I'm thinking of something that can use the same MySQL database and probably has the same front-end ui. I have really liked Drupal and I feel its data model with fields and such is great, but I think PHP is really holding it back and making it unnecessarily slow and complicated.

Node.js particularly interests me with its event-driven, non-blocking I/O model. Serving a single Drupal request can take a few seconds, even if the server has no other traffic simply because of PHPs blocking IO model. Each time Drupal makes a SQL request it has to do round-trip to the database. Even if the database and server are on the same machine, this communication takes time. Whereas with Node.js many database requests can be done concurrently.

Also, I feel the PHP CGI style model of reloading all data between requests simply wasteful. I feel like a servlet-style architecture where a long running process can maintain state between requests would be super advantageous for something like Drupal. Right now Drupal has tons of caching in order to make loading all the data fast enough, but this is painful because it's complicated and then one needs to be flushing the caches a lot while developing.

Has anybody else felt these same pains and thought there's got to be a better way?

Comments

Services

akayani's picture

You could always do your authoring as normal but provide an interface using services. There's a Drupal mobile example of that.

https://www.drupal.org/project/drupalgap

I think if you want a different backend language you should use a different CMS.

Non blocking (async) in PHP

mikeytown2's picture

I created 2 projects due to this issue.
https://www.drupal.org/project/httprl - HTTP Parallel Request & Threading Library. Using the latest dev of HTTPRL you can easily run a drupal function in the background (you can do it without the latest dev, just requires more code). When to use: it should be an expensive operation that you need to do ASAP (not cron) and is slow. Here's a simple example:

Normal way

<?php
watchdog
('httprl-test', 'background watchdog call done');
?>

In the background

<?php
httprl_call_user_func_array_async
('watchdog', array('httprl-test', 'background watchdog call done async'));
?>

Works just like call_user_func_array(). The example file has some interesting things in it http://cgit.drupalcode.org/httprl/tree/examples/httprl.examples.php?h=7....

https://www.drupal.org/project/apdqc - Asynchronous Prefetch Database Query Cache. This allows for the database cache to function as you'd expect; cache writes use async queries so they don't block, cache items are prefetched so when it's being requested it's already there.

You can check KeystoneJS. A

puagardian's picture

You can check KeystoneJS. A nodejs based CMF with Drupal-like fields model.

Reimplementing Drupal in

gordon's picture

Reimplementing Drupal in another language is basically forking Drupal and any new innovations will not be implemented. You will be stuck in time.

With Drupal 8 and also with 7 but not as nice you can do a headless version of Drupal and use the Jason api to get the information out. Then you can implement the front end in node without any issues.

Also it means that you do things like add varnish between node and Drupal for make the responses even faster.

The new twit.tv does exactly this with Drupal 7 and node. For kitchens did this site and a t is very good.

Gordon

--
Gordon Heydon

I know I'm late, but I wanted

coreyp_1's picture

I know I'm late, but I wanted to jump in.

I'm actually working on a Drupal-inspired framework in Node.js, because I have absolutely hated all of the options that I have seen so far. Let me know if you're interested in working on such a project. For now, I'm toiling away on my own... :) The biggest problem is that it is not even alpha quality, as I am working on getting a proof-of-concept together.

If you're curious, I have a 3-part blog post about why I feel this is necessary, and it actually came about because of security problems that I saw on most Express-based solutions.

The crux of my opinion boils down to this: Every framework that I have seen falls into one of two camps. Either it is too narrowly defined and does not support a pluggable architecture (Drupal spoiled me!), or it is so loose that you have to write tons of glue code for each project.

I want a framework that is ultra flexible. Drupal's power is that it is opinionated in how things fit together. Drupal's limitation (IMO) is PHP. Granted, a web frontend is needed for most web-based projects, so that is what I am working on first, but the intention is to create a backbone for various types of server tools. Examples might include an email server, configuration management (a Chef or Puppet replacement), database management (who needs phpmyadmin anyways?), websocket or webRTC middlemen, etc.

Obviously, it's a big job. But, hey... that's what Open Source is about, isn't it?

P.S. - ES6 is awesome, so that's what I'm using for the backend code.

Hey! Nice! I was thinking

gor's picture

Hey!

Nice! I was thinking about having Nodejs framework as a Drupal like one.

The big difference here is that nodejs has a power of JavaScript:)

I mean it's really cool to combine hooks and asynchronous language behaviour!

Find me on gitter.im.

I am usually on backdrop/backdrop-issues channel.

This sounds interesting,

Fabianx's picture

This sounds interesting, please post back when you have some code.

The real question is:

What is the core of Drupal you want to port?

Is it Entity? Fields? The request mechanism? Hook compatibility? Database layer? Cache layer? Menu system? Breadcrumbs? Block? Poll? Statistics? Throttle? Form API?

And is it D8 or D7 you want to port from?

I think that main idea is

gor's picture

I think that main idea is port a HOOK idea by itself.

When your custom module provide and register callbacks (if we talk about NodeJS) to specific events.
Core by itself should provide register functionality and callback request to modules.

This one is similar to event Dispatcher in D8.

Literal implementation of hook_*** by itself is not really applicable to NodeJS ideology, due to async processing.

albertosouza's picture

@coreyp_1 Why not use one framework that already has some drupal features like the We.js.
We.js have:

  • Form generation based in models or json with templates for fields (use for drupal form API)
  • ORM with Suport for mysql, postgresql and mssql
  • Hook system with run order: https://wejs.org/docs/we/hooks-events
  • Accessibility enhancements (need contributors): https://github.com/wejs/we/issues/112
  • Plugin system
  • Theme system
  • ACL plugin
  • Auth plugin
  • Template override (theme templates can override plugin templates)
  • Generator for blog project
  • All node.js power for make simple APIs
  • Install and update functions like in drupal

And others usefull features ...

You only need to map drupal database and change drupal php code to we.js code

Link: https://wejs.org/
In github: https://github.com/wejs/we

Having used a couple of node

Greg Boggs's picture

Having used a couple of node frameworks, the thing I love most about Drupal is having a standard field UI and view modes. I mean, generating CRUD classes from database tables is good too, but sometimes, I just wish I could drag and drop a field on a display or set a field to multi-value with a drop down menu.

We built the platform you are looking for...

travist's picture

It seems that the platform you are asking for is very much aligned to what we built @ https://form.io. @corey_p, you would be interested in this (good to hear from you, btw). Disclaimer: I created Form.io, but have been a long time Drupal developer and advocate.

This platform was built to have some similar concepts to Drupal, but is much different in a lot of aspects since it is really meant to be a platform for "serverless" applications. Here is the presentation we gave at DrupalCon New Orleans to talk about it https://www.youtube.com/watch?v=0MPI32kR92I.

Here are some of the main differences.

  • Built entirely on Node.js (Express) and highly leverages Asynchronous I/O
  • Forms are JSON powered renderings on the front end and completely API driven.
  • The server NEVER sends markup to the client. Apps are stand-alone and headless using Angular.js or React.js
  • Authentication uses modern JWT token based authentication
  • Resources are created using a drag-and-drop form builder.

I encourage you to read this walkthrough tutorial which should give you an idea what it is like to build an app with Form.io.

https://help.form.io/tutorials/walkthroughs/#servicetracker

It is MUCH different than Drupal, but at the same time leverages the modern "serverless" application practices that Drupal is trying to head toward anyway. Oh, and we also just released a module for Drupal (https://drupal.org/project/formio)

Hope this helps.

Travis

Elixir?

cleaver's picture

I've been thinking along these lines, but I think there's better options than Node.js. Has anyone considered Elixir or another functional programming language? Elixir or Erlang offers some great features for speed, high availability, and parallel processing.

I haven't done anything so far... It's just at the shower thoughts stage :)

I think Node.js has bigger

thomas4019's picture

I think Node.js has bigger community and JavaScript has the advantage of being so easy to pickup and hack on, like how Drupal's use of PHP makes it accessible. For some reason functional programming still isn't mainstream.

That said, Elixir does look like it has some awesome features, especially the ability to make DSLs.

Thomas Hansen
www.ThomasHansen.me

Definitely a bigger community

cleaver's picture

Definitely a bigger community and ES2015 is actually getting to be a nice language. Elixir is getting a lot of interest from the Ruby community, but would be still further in the future before it could gain some traction.

I just don't find myself thinking about Javascript in the shower :D

Elixir?

cleaver's picture

Blast! double post

Expressa (my own alternative)

thomas4019's picture

I'm glad to see there's some growing interest in this. It just seems like Drupal's become too big for PHP. In some ways I think it would amazing to write a system that uses the exact same database structure as Drupal (for easy migrations) but that would be a monumental effort.

@coreyp_1 I read over your posts. Cool idea! But it seems very focused on the Drupal model where a form is generated and rendered on the server and then filled out on the client. I see the trend to be moving towards powerful frontends using Angular/React which process the data and then post all the data to the server (and only at that point does the server do any validation). I don't see why you need the form generation step and why that couldn't simply be baked into the frontend.

Lots of people are using Drupal in headless setups where they write their own frontend and only use APIs. I've written a basic cms which could be a useful alternative in that kind of setup. It's currently usable at https://github.com/thomas4019/expressa. It provides a prebuilt front-end for managing your "content types" as well as CRUD on that data. It let's you choose whether to store in flat files (which makes version control a lot easier) or a database (postgresql or mongo). Then you write your own frontend and only interact with it using the APIs it provides.

Thomas Hansen
www.ThomasHansen.me