288 points · by keithwhor · 10y ago · 168 comments
This looks like a node framework that I'd really enjoy using - first time I see a framework that feels like it fits around ES6. For me personally, having a good ORM and models layer, coupled with migrations have been a deal breaker in choosing a framework, and I'm very happy to see that here.
Is everything written from scratch or are there dependencies? If so, it sounds like its actually quite an opinionated microservice architecture.. Lately I've felt like microservice and microframeworks have gone hand in hand :)
Great job!
Very happy with the lessons I learned throughout the process and the end result. Experience with Django and Rails design patterns was a tremendous help.
Still, I look at things in Django and get angry that they were not MORE opinionated, like Rails. Like, not having a decent REST abstraction out of the box is almost unforgivable in this day and age.
I think Django's evolutionary decision making has been nothing short of fucking awesome. They've consistently waited until a clear, mature 3rd party winner has emerged for problems before integrating them. When those solutions are integrated, they're battle tested and not going to bite you into the ass.
Django's team is very aware of where their weaknesses are, and they're working on them:
We've been awarded $150,000 to help fund the development of Channels, the initiative to rewrite the core of Django to support (among other things) WebSockets and background tasks, and to integrate key parts of the Django REST Framework request/response code into Django, such as content negotiation. Together, these projects will help considerably improve Django's role of backing rich web experiences as well as native applications.
https://www.djangoproject.com/weblog/2015/dec/11/django-awar...
Rails opinionated approach lead to heavy churn in the 2 -> 3 -> 4 transitions. I don't want to deal with that.
Will still have to see where people run into the most trouble and go from there. But I would enjoy it if people could pick up Nodal and walk away confident they could build an ES6 app from scratch.
The community has stepped in here.
Django Rest-framework provides one of the best approaches for creating restful apis that any web framework has to offer. For me, using Django is inseparable from using Django Rest-framework. Its what makes working with Django great.
Nodal by comparison does a lot of great things like Django does, but without the robustness of a rest framework behind it, Nodal seems to have created another good framework but not something new and better.
It was pleasing (and a little surprising) that everything was almost exactly how I expected it to be. I watched the video, got started and rarely needed to go back to the API docs. It actually feels very light and natural despite the fact that it's already quite fully featured.
Language preference aside, I feel as though rails might be a better Django than Django is in almost all areas that you define as deal breakers.
There's nothing like ruby/rails (I love me some rspec!), but ultimately it came down to lang pref for me, and maybe performance (dev reload cycle mostly). Plus, python has a lot of very interesting stuff in machine learning and science.
- Node's package manager npm is fantastic, and (imo) gets package management more right than 90% of other package managers
- There are 1000s of high quality actively maintained modules on npm to get you started on things (and 1000s of garbage ones, so you have to be careful)
- The "holy grail" web app architecture (server rendering of frontend JS components coupled with client side rendering in a SPA) is only possible by running some JS on the server
- Sharing JS UI components between the backend and frontend is a huge DX and productivity win
- Another huge maintenance win is using the same language across the whole stack (frontend, backend and devops/automation)
- With ES6, JS is slowly turning into a pretty cute language, check it out :)
- A nice level of cross-pollination between JS and those geniuses in the ClojureScript community is bringing some really nice functional programming approaches and projects to Node/JS
- You can use Node and JS to compile to both native desktop apps and native mobile apps. Having a centralised UI library of JS components that you can leverage for your desktop app, mobile app, frontend SPA and backend static rendering sounds pretty good to me!
The quality of node package is very bad in general. Like the most part are totally garbage. I don't know from where you come and what you used before, I worked only with java, php and ruby for the backend and in those i found:
- far higher Documentation quality... like, node modules documentation is not even REMOTELY comparable: it is often extremely outdated, with very poor examples, the most of the times these example are not even working or are using functions deprecated since 3-4 versions of the module itself.
- a infinite amount of bugs and undocumented behaviors rarely already reported and, when reported, just ignored for months. I usually would find infinite workarounds instead of solutions
- extreme use of "I can do it better, so here my fork". I passed the big part of the time running from bug report to bug report and reading in the comments discussions about "The main maintainer of this package does not want to solve this problem of mine... so i made this other module, totally identical to this one but I just added this little hack, which totally broke the standard way of doinf things of this module, some functionalities I needed and never implemented the last 8-9 months of commits here." and chain this. Like this happened a dozen time each months when someone suggested "Why we don't try this module that says it solve our needs?"
- No standards anywhere.
It's true, you have to be careful ... there are so many npm modules that there are many garbage ones too. But there are many very high quality ones too. Be more careful about how you choose one, and if you can't find a good one for your needs, then don't settle for a bad one - roll the feature yourself, or adjust the functionality of your app. But in my experience there are high quality modules available for the major components of apps.
Bundler and hex, for example, are faaaar better--just consider how long it took them to figure out shrinkwrapping, or flat structure to support Windows.
All of my recent projects have been isomorphic react apps. I build my app like it were a fully client-side single page web app, but I get server rendering when there's a new http request. Once the page has rendered, the web app takes over and uses history pushState. There are very few pieces of code that aren't used in both places. Once you get the hang of it, you very naturally create mockable interfaces that can be swapped depending on environment.
In my opinion, this is pretty much the only category that makes JavaScript "Best-in-class"; It's the easiest language to build isomorphic web apps.
* Babel - ESNext - JSX * Gulp * Browserify - Incremental * Express * React router * Rolled my own flux - This was interesting because I didn't truly understand flux when I started - I _get it_ now
The routes on the server are the same routes on the client. When the server renders, React/ReactRouter take over on the client and use history pushState.
And that's actually about it. There aren't any other major libs that change the nature of the project.
One thing I'm looking to do next is get hot reloading working and to somehow cut down on the initial compile times.
JavaScript is becoming the web darling (or it already is?), whether we like it or not. And with some nice syntactic improvements ES6 brings, I don't mind.
Meteor excels at this.
I wonder, will it be still as popular if WebAssembly let us use any programming language on the client? I mean post MVP WebAssembly with support of GC, DOM, and so forth.
Dart, ClojureScript, TS (technically JS superset but still a considerable improvement) are just the ones I've used.
And I'd rather use both of them on server (Dart/Clojure) than JS.
There are other languages as well.
ES6 is a pain in the ass - no browser supports it and using transpilers + polyfills and the JS build/package tools to set that up is a PITA that only grows as you add dependencies and it bloats your code size to be comparable or larger than the compile-to-JS languages without making the language significantly better.
Don't get me wrong I think all those experiments (if I may) are nice, but if I were to develop an interface in Dart/CS/TS today, I'd have serious problems hiring people that know one of those tomorrow.
I don't see how using Dart, TS, etc. make it any asier, and with the setup I just described, you're using Javascript top to bottom. I have an Angular project set up this way, and that allows me to run the unit tests in Node on the command line.
And why would you write ClojureScript to use on the server, when you could just use Clojure?
Plus you've somehow managed to state that JS developers are not decent enough.
1) Bad concurrency model -- callbacks, promises and futures are in general inferior abstraction model compared to green threads, actors, regular threads. Performance-wise it might do well in some scenarios but you are forced to use a more complicated abstraction to get that performance It is not worth it. In general it is appealing because it looks simple in small demos, as applications grow it becomes a mess.
2) npm modules are easy to use and that's great. Good model (well maybe except for deep nesting which breaks based on max path in say Windows, but I hear they are fixing that). The problems I found was that a lot of modules were of low quality. Code half-finished, buggy, developer moved on to something else, etc. Somehow it seems more so than say in the Python community.
3) Javascript is not the best language. There is a reason there is a "Javascript: The Good Parts" book. Because there are lot of crazy decisions made in it originally and a lot of bad "parts". If there was a choice between FORTRAN, Cobol and Javascript. I would pick Javascript hands down, but there are other languages out there today.
However. If all you know is Javascript and you want to write a small demo, then go for it. It will be the least friction.
So with all this complaining and whining, how about some constructive stuff. What language / frameworks might be more interesting / better.
1) Go : good concurrency model, supported by a large community, good performance. Lots of big companies use it.
2) Elixir : new kid on the block, fun, one of the friendliest communities. Probably best concurrency model -- actors. It uses Erlang's VM, so that part is rock solid, battle tested for many years. But not as many libraries. But can use existing Erlang libraries from it. Also best for reliability and fault-tolerance.
3) Python : easy to learn, lots of libraries, lots of material how to use it. This is my go-to language to get stuff done quickly. Try Python 3 if you start from scratch.
4) Clojure, Scala, Java: run on JVM. Battle tested, probably lots of libraries. Personally not as familiar with it, most enterprise and big sites out there run on the JVM currently.
It's great you like Python. Use a Python framework. You can point out Javascript's warts and we can laugh at the Python 3 migration. (And really, both of these criticisms are out of date. Javascript is _fine_ these days and Python 3 is moving towards backwards compatibility; sure Javascript has warts, but that's because it's backwards-compatible. You know, like... never mind.)
I don't like many things and like other things. All in various degrees. So I shared my experience.
But you seem to be interested in what I like, so I'll share more. I would say, in general I am not really a "$X language" developer. A lot of people say "Oh, I am a Java developer" or "A Node developers". I am not a Python developer, or Erlang developer. I am a developer who solves problems. And languages are tools ( so far I used Javascript in the past, as well as Erlang, Java, C++, C#, and yes, even FORTRAN ).
The point about Python was that currently, most tasks I had to do, were made quicker and easier by using Python. Some are solved better by Erlang, some by C#.
Javascript and Node I found had enough negatives so it seemed helpful to share that too.
> Obviously, if you don't like javascript, move on.
I didn't know this was Javascript land and I wasn't allowed to come in without proper credentials. (See note about "friendly community" regarding Elixir in my original post, that wasn't by accident. I didn't want to say anything more about Node community, but I will now -- yeah it is not the friendliest, lost of insecurity and angst in it, which was another turnoff to me personally).
The reason why JS + node is popular is becasue it's pretty good at each of the metrics you mentioned. Even though it's not best in class at any one of those, it is well balanced for many tasks. Many other technologies are either too slow, too low level, too hard to scale, or too cumbersome to work with.
But if you go back to the origin story of Node, it's all about libev (though it now uses libuv for the same purpose) and that pervasively-asynchronous mindset. JavaScript was chosen as the developer interface because it met the need to support that asynchronous philosophy. The result is that everything in the Node world is asynchronous and asynchronous is the path of least resistance for the developer. Other platforms that weren't conceived with this mindset often force developers to fight to be asynchronous.
> It seems like whether you're aiming for ease/speed of prototyping, pure performance, a good concurrency model...
It's a mistake to look at JavaScript as a fit for all of this. Instead, you should consider how the Node platform fills the need. For easy of prototyping, it's not JavaScript that makes Node excel, it's npm. The only package management system I've found that I prefer to npm is Rust's Cargo. And npm is still well ahead of Cargo in the richness of the package ecosystem. For pure performance, you can always write a native Node addon [2]. And, as mentioned, while JavaScript isn't concurrent at all, the Node platform provides the concurrency model in a way that has proven to be scalable but without most of the pain that comes with writing concurrent code. Writing concurrent code is hard...that's not news. The Node framework make writing concurrent code significantly easier by creating abstractions that hide the the fact that code is concurrent.
I know it's bizarre to look at it this way, since you would be writing most of your application logic in JavaScript, but try to look at it as an implementation detail and consider the advantages of the Node platform and the ecosystem that surrounds it. When you take this perspective, Node becomes a lot more attractive than the JavaScript language is on its own.
Lately rails got their socket support, and python3 has been getting better support through async, but in both those languages, I've long felt its been pretty experimental, and there simply hasnt been a performant option available that has a good opinionated framework.
Nodejs has performance going for it at least if you look at the language benchmarks, and now with ES6, it feels like the language is finally starting to shape up.
(It will. I just want to make sure I do integrated socket support right. I don't want to chase realtime frameworks because that's not Nodal's value prop, but I do want it to be easy to create socket connections when they're needed.)
For me, the jury is still out on whether I will be able to model my domain well in a language like Elixir.. I love Haskell, but I sometimes wonder if its a healthy attitude to be so stubbornly against OO. That said, I understand the arguments against essentially `this` and mutability. Any pointers on how to model your domain model in FP would be really welcome!
One major advantage I can see is if you're a full stack dev. You don't have a switch languages when you're building the backend and the front end. Some people may not see this as an advantage, but personally it takes some time for my brain to switch to javascript for the front end when I've been using either java, python, or ruby for the backend.
The right tool depends on the requirements. If there's no special requirements then I don't see why javascript can't be a substitute for ruby, python, php, or perl on the backend.
> you would use something like couchdb instead of a relational db
I'm not sure this is a good analogy since javascript (as well as the backend languages that it seeks to substitute for) is more of a general purpose tool, and not a super specialized datastore.
out of curiosity, which language + library/framework pairs do you think is a better tool than javascript + nodejs when evaluated along each of your 3 metrics?
I moved from python + flask to nodejs a while ago, I still thing nodejs is better than python + flask, but I'm trying to move away from javascript on the backend.
ease/speed of prototyping: Ruby (or Python, even), Go, [Crystal]
pure performance: Go, Rust, C++, C, Scala, [Crystal]
a good concurrency model: Erlang, Go, [Crystal (similar to Go)]
A small note about why Crystal is in brackets: The language is very young compared to the rest, and it's currently very volatile in terms of syntax/API stability, or even compiler semantics, but it looks very promising and it's quite easy to get started with it or to become a contributor because the compiler is written in itself. http://crystal-lang.org/ (Sadly, /docs is a bit outdated and misses some crucial parts, but /api is very comprehensive).
I should do some real world benchmarks on Elixir vs Go for my own purposes.
But I'd imagine if you really care about microseconds, you should use a language without GC.
Rust would seem a good choice.
I think that this is specially appealing for people that are building offline enabled clients, which end up having to handle more business logic than usual for client-side code.
If you structure your ops to be reorderable and composable you can get nice stuff like multi user editing, arbitrary undo, multi data centre synchronization, etc.
See the google docs papers for more details.
For example I'm taking some front end javascript I've been working on and putting it on the server (using another new node framework based on Laravel that so far I really like: http://adonisjs.com ) and it would definitely perform better if I rewrote it in Go or Elixir - but even if I could figure out how to do that if the thing takes off I could never find anyone to help me with it.
With JS though it should perform reasonably well (node is supposedly pretty fast where it counts, nonblocking and all that) and I could hire a danged high school kid to give me a hand with it if it somehow succeeds. I imagine a company like Walmart was thinking along those same lines when it chose Node.
(These comments are just from watching the first video.)
But how is this next-generation? It seems to be very inspired by established widely used web frameworks such as Ruby on Rails. With elements such as ORM, routing, controllers, HTML templates.
It also seems to require a lot of code generation. Is that really constructive? (What happens if I edit the various generated files, would I still be able to add field to a record using the command line tools). Couldn't you have moved some of the boilerplate into the framework?
Why not use ES6 imports? (Rather than require / Nodal.require)
Why create an ORM rather than use a JavaScript-orientated NoSQL database? (mongo, couch etc.)
I could be way off here (and I probably am) but shouldn't frameworks abstain from being too opinionated about the particular technologies that you use? The database (or type of db) you choose seems like something that should be based on what your application's requirements dictate not what your framework prefers right?
If a framework can't offer me this kind of functionality, why would I want to use it over a library with all the control benefits that brings.
NoSQL has its place, but it's usually not the best choice. Any "comprehensive" web framework should cater to the needs of RDBMS users at a minimum, with support for NoSQL as a plus.
What are the benefits of "import" over "require"?
Require is a regular function rather than a directive, and is probably needed for this framework to automatically find and load all controllers, models, etc.
Writing tests for the Controllers would be a real pain, because you would have to do a lot of ad hoc mocking, it would be better if the controllers would return something instead of calling the this.render.
You might be able to make the the controllers into POJO's.
The file naming conventions are weird, mixing camel case coding with underscore filenames is just unnatural.
Having a custom 'require' function in the framework, means that any code I write, is dependent on the framework itself.
The automatic migration generation is pretty sweet.
Coupling the data models with DB configuration is a bad habit.
The use of static methods to define aspects doesn't feel natural.
Having one big routing file doesn't scale, the routings should be expressed in the controllers.
Overall I would recommend adding in TypeScript, it would allow a lot more cleaner code.
1. POJOs are ugly and you must revert back to using Object.create() for inheritance, breaking the design pattern of using ES6's class syntax.
2. PascalCase class <-> camelCase instance <-> underscore_filename <-> underscore_tablename is a standard borrowed from Rails and easily managed through the npm inflect module (i).
3. It's just a shortcut. You can use normal CommonJS require(), you'll just have to resolve the relative path yourself.
4. Thanks! :)
5. Models can exist without database connections and with manually defined schemas. If you check through the commit history, I used to keep database and model completely separate but there was way too much code reuse / smell (passing in a db as a parameter on every function call).
6. The alternative is setting properties with ClassName.prototype.value = 'xyz'; or ClassName.value = 'abc'; Static methods provide an easy to read + concise way to do this for you (and take care of additional functionality). Also borrowed from Rails.
7. Chose that pattern because it is very explicit / ordered. How do I determine what order the routes are hit when I specify them per Controller? And if I define them on the Controller, that means I need to load all Controllers globally on Application start.
8. I'm happy with how clean the code is now. :)
Having the framework be batteries-included is nice, but also nice would be decomposing it into modules. For a good example of this, check out the Hapi.js server ecosystem. Lots of different plugins, and if you want object validation outside of the hapi.js world, you can just use Joi alone. It lets me mix-and-match stuff. A concrete thing here is the ORM layer (which hapi.js doesn't have). If I could pull your ORM out from the server stuff, I'd be a lot more likely to take that part at least for a spin.
promises are rad, and I know I can just use Bluebird's promisifyAll to wrap your code. But still, it would be nice if I didn't have to muck around with that and async methods called without a callback returned a promise by default.
middleware is rad, it lets me abstract out pre-processing that happens on (say) every POST route to validate parameters. It doesn't look really feasible to do that with this system. I'd basically just have to bake all that into the post() method, which isn't super-modular and is probably harder to write unit tests for.
can't say that I'm wild about regex routes by default. I dig stuff like 'items/:itemId' with named parameters in a microsyntax. Makes life a lot easier.
Basically a lot of my routes do stuff like parameter validation (I store specific criteria on the model class, but apply them in the route), creating a new object from validated post params, loading from the database, storing to the database, authorizing and authenticating, etc. Then my route definition declares the per route middleware and the specific controller only has to encapsulate route specific business logic.
I could do that just by putting it all in a utils package and calling loadItem(), validate params() etc at the top of each handler, but that feels less elegant.
It may be that I've just been using hapi.js for too long, the modularity and composition in that framewrok.is quite elegant, IMO.
For those looking for an "enterprise" alternative to Express, give Hapi a try! It's very mature, has tons of extension modules (as pfooti mentions), and basically can do mostly everything you need without your needing to write much glue code.
Also, if you use typescript, it has a .d.ts file at Definitely Typed. (I wrote it)
export default class ...
would be the clearest and least bug-prone and satisfies the "no extra closures" complaint. Considering you're buying into other ES6isms, why not use that one too?Edit: I'm on my phone and I zoomed all the way in, and I see that it's actually white text, which is still bad.
http://webaim.org/resources/contrastchecker/?fcolor=00E1FF&b...
Good job btw, this looks very nice as an alternative to the micro-framework world of Express.
Anyway, I found one or two interesting things reading the source code, so even not being a Nodal user it delivered value to me.
I'm really flattered you found things you thought were interesting! Would you care to share?
This is the major reason why I have learned to be cautious with getting wowed by the apparent simplicity of micro frameworks.
At the very minimum, I want a framework to have an opinionated model layer with migration support, and chances are you will get trickle down benefits from frameworks that have opinionated M layer..
Look at djangos form abstraction for instance. Or the way validation is handled in Django models, which in turn opens up for the possibility of creating a neat REST abstraction. These are the types of abstractions that you end up writing yourself or not writing at all when you go the 'light framework' route, but they are almost always handy and will save you time.
Sometimes you want something like Rails or Django. Then express and similar "a la carte" solutions won't help you and you'll end up re-inventing frameworks and re-implementing the same old bugs and mistakes.
Sometimes you just want a small single-purpose server. Then Node and NPM shine and big frameworks seem like unwieldy behemoths in comparison.
Personally I'd say Node isn't a good choice for the former and you'd be better off with something powered by Ruby, Python or PHP (i.e. Rails, Django etc). And I say that as someone who's been almost exclusively using JavaScript for the past couple of years.
Other notes on the documentation:
* Very little info on how the templates (views) work. Can I use a different engine for them? No info about that.
* (just as an example of many) I've noticed that a scheduler is implemented and that it's mentioned in the site. It is also noted on github that there's no info on the scheduler yet. So, why would you include the features that no one will be able to use unless they're willing to get into the source code of Nodal itself?
I see that the project has been going for almost a year now and it looks like it's going a great direction. Just needs a more user friendly documentation to be fully usable, I'd say.
From a quick glance at the documentation, the "server types" seem very sensible.
I appreciate the DSL-for-problem approach, but this is kinda exactly what some of us were worried about.
It may be a great framework, but that strikes me as an odd point to make about the project.
Are soft deletes planned in the future? I saw that cascading is on the roadmap.
It could the best framework ever, but without an example all that stuff is useless. The video could help, but it is a) way too long and b) appears to be pretty slow in showing the meat.
Do you care to elaborate further?
Also, if you read the docs of any major API implementation, you will find examples in python, php, java, etc. but I'm yet to come across a node example. Node ain't ready for the real world yet.
https://github.com/nodejs/node-v0.x-archive/wiki/Projects,-A...
You're right. PayPal, Uber, Walmart are all tiny little nobodies. And I'm not entirely certain what api implementation docs you're looking at, but I've yet to say, "I need service X" and not find a node.js API wrapper already built.
Projects like Yammer are really small and not known? Okayyyy.
You should really reflect your view of the world.
Netflix, I actually enjoyed their video on how they debug node in prod[0].
This quora article seems to substantiate my 'enterprise' claim somewhat: https://www.quora.com/What-are-the-biggest-websites-built-wi...
About 5 years tbh: https://blog.risingstack.com/history-of-node-js/
"hardly find any large, well-known website being powered by node"
* Netflix - https://www.talentbuddy.co/blog/building-with-node-js-at-net...
* New York Times - https://www.talentbuddy.co/blog/building-with-node-js-at-the...
* PayPal - https://www.talentbuddy.co/blog/building-with-node-js/
* Medium - https://www.talentbuddy.co/blog/on-building-with-node-js-at-...
* LinkedIn - https://www.talentbuddy.co/blog/building-with-node-js-at-lin...
* Uber - https://www.joyent.com/developers/videos/node-js-office-hour...
It's a tool, and like every other tool comes with its pros and cons. I am not saying Node is the perfect fit for any project, because it isn't. However stating it isn't used and almost a decade is just wrong.