Node.js and MongoDB Turning JavaScript Into a Full-Stack Language
Nerval's Lobster writes "For all its warts and headaches, JavaScript has emerged as the lingua franca of the modern Web, arguably second in adoption only to HTML itself, which obviously is just a markup standard rather than a full-fledged programming language. It's effectively impossible to launch a sophisticated Web project without making extensive use of JavaScript and AJAX dynamic loading. That's precisely why recent projects that move JavaScript beyond its usual boring domain of defining in-browser interactivity are so interesting — because it's already dominant, and growing even more so. Writer and software developer Vijith Assar argues that Node.js and MongoDB are turning JavaScript into a full-stack language. 'In the grand scheme, Node and Mongo are still quite new; for the most part, ace JavaScript developers who can write brilliant code on both sides of the request transaction have yet to emerge,' he suggests. 'But if and when they do, the things they build could be jaw-dropping.'"
In the grand scheme, Node and Mongo are still quite new; for the most part, ace JavaScript developers who can write brilliant code on both sides of the request transaction have yet to emerge, but if and when they do, the things they build could be jaw-dropping.
Can any real developer explain why having a javascript backend would be any different to any other backend in such a way where something jaw-dropping could only be the result of the javascript backend?
No, it's fanboy hyperbole.
lol
go home Nerval's Lobster, you're drunk
'But if and when they do [emerge], the things they build could be jaw-dropping.'
These mythical ace developers who are brilliant at browser and server javascript will never emerge in large numbers. "full stack" javascript will not produce anything any more jaw-dropping than any other stack is already doing.
I've been using node.js and while javascript is become passable as a browser language, it still sucks as a server language.
I wonder if anyone ever thought of letting a JVM run in a browser and use those for the full stack as a replacement for javascript.
(Edit: yes, I've heard of java applets before)
So instead of having one portion of my stack vulnerable to hundreds of exploits, now I can have the ENTIRE stack vulnerable to hundreds of exploits. Sign me up!
sudo make me a sandwich
What does full-stack mean? Is this akin to a "fully-loaded" car?
I wouldn't necessarily pick Javascript on its merits as a language, but for a language as dynamic as it is, it has very good optimizing compilers, probably research state-of-the-art for this kind of language (Google's V8 engine is largely built by ex-Smalltalk researchers). That gives it some advantages over, say, Python.
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
Javascript isn't really a very good programming language (its lack of strong typing and lack of pointers are two things that often frustrate experienced coders). The only reason it's so popular is that it is a universal standard for client-side scripting in the browser. If you want to run code on the user's web browser, you have to use Javascript.
On servers, that doesn't apply. There are much better languages, no matter which platform you prefer. And MongoDB isn't particularly impressive, either; it's basically a database for people too stupid to understand SQL.
ace JavaScript developers who can write brilliant code
There are so many things wrong with that statement, my brain hurts trying to figure out where to begin
As noted on slashdot a whole back Fabrice Bellard has written an x86 emulator out of javascript... and made a whole linux system in a browser: http://bellard.org/jslinux/
With other technologies, (gwt etc) javascript can be thought of as a compiler end result language. Yet, even a 'primitive' or difficult language is just another means of expressing a concept that is in the programmers head. There have been programs coded in assembly language that were amazing, fantastic and clear. Others were so efficient that they were an obfuscated mess to the casual observer, and only understandable after knowing the hardware and assembly language intimately.
Javascript is just a language, leveraging frameworks can make it more 'sophisticated' but.. .it is just a way for the programmer to communicate with the hardware to make it all happen.... A good programmer knows how to make hardware happen.... the language is just a different vocabulary.
>> ace JavaScript developers who can write brilliant code on both sides of the request transaction have yet to emerge,' he suggests. 'But if and when they do, the things they build could be jaw-dropping.
You mean they would be as good as real programmers? (i.e., People who use Javascript on the client side and something meatier for the server app.)
The real thing that's turning javascript into the lingua franca of the web are really three things:
It's an inside-out stack.
It takes a man to suffer ignorance and smile
Be yourself no matter what they say
Python, Ruby, Lua, PHP, Lisp, Perl, Awk, etc. are bad : they lack pointers and strong types. Oh and lets not forget type coercive language in respect to strings (or pointers since that was brought up) ...
Javascript is a terrible language for back-end development. It's a terrible language for _front end_ development but it's all we've got. Microsoft tried something very cool with Silverlight (.NET in the client) but it crashed and burned. So why would one want to use Javascript when C# or Java (or other shitty but still better than javascript scripting languages people seem to be into, I guess) are available on the back-end?
Reminds me of the below-average players in World of Tanks, always grinding for the Next Tier Perfect Tank that will get their winrate in the black for sure.
Just get better at coding / learn to master the tanks you already have. There are no shortcuts.
I couldn't even log into my credit union or broker without it!
Financial web applications probably use JavaScript to store a cookie that verifies that this browser has previously been used to access this account. This makes the browser the second factor in a two-factor authentication system.
And all it does is make pages more cluttered
Not always. JavaScript lets a web page hide a particular element until the user expresses interest in viewing it by clicking it.
harder to use
With JavaScript, a user can (for instance) click to expand help for a particular field of a form without having to navigate away from the form.
longer to load
Without JavaScript, the only way to expand or collapse an element in a document, such as an element in a tree or an aside that has been hidden, is to follow a link or submit a form that results in sending the whole page back. This whole page takes long to load.
takes up bandwidth
Updating only what has changed on a page takes up less bandwidth than having to send the whole page all over again.
Google. No scripts there but immensely valuable.
If Google Search doesn't use JavaScript, how do the Suggest (drop-down completion box below text input) and Instant (replacement when the user pauses typing) features of Google Search work? Besides, Google also produces Gmail, Google Docs, and YouTube, which use plenty of JavaScript.
Python has pointers in the same way that Java has pointers: objects are passed as references. Besides, there's a difference between strong typing (automatic coercion) and static typing (variables can hold references only to a particular type and types that extend or implement it). Python has strong types (1 + "2" raises TypeError) but, like JavaScript and PHP, lacks static typing apart from a few specialized numeric containers (such as array.array).
Sharing a single code base between client and server is a huge benefit for any application. Nobody likes to write things twice.
Pretty good is actually pretty bad.
This one won't beat the Turing test yet, but keep trying!
Pretty good is actually pretty bad.
Sometimes "a much better development team" is a larger and therefore costlier development team.
Besides, sometimes I want the code on the client and the server to do the same thing, and the easiest way to do that is to run the same code. (See Don't repeat yourself and Once and only once.) Say I want to validate input on the client for speed and offline capability and then revalidate it on the server for security. With a common language, I can reuse the same validation functions on the client and server. Without a common language, what's the standard practice to formally verify the equivalence of the client-side and server-side input validation code?
Fabrice Bellard could make an x86 emulator out of a paperclip, some spare change and a couple of matchsticks.
Just because you can do something doesn't mean it should be used as a production product.
https://www.facebook.com/digitizeicm -- Show your support for the digitization of the Iron County Miner newspaper archiv
One advantage I could see in having JavaScript used on both client and server sides is that ultimately we could imagine new frameworks that would completely hide the separation between client and server. After all, we're using MVC anyway, might as well have all components in the same language so that the glue part is as seamless as possible. Wouldn't it be nice if you could have an IDE that gives you the impression that you're programming a regular desktop application, but that would take care of the deployment aspects? And once you get there, you can imagine higher level, languages that would generate the JavaScript for you if you're not a fan.
"In our tactical decisions, we are operating contrary to our strategic interest."
All they need to do now is shoehorn PHP and MySQL in there somewhere, code it all in notepad and you have the development stack from hell.
and recovering from an exception in node-js is next to impossible. You really have little choice but to reboot the instance.
If you post it, they will read.
This seems to happen every time someone confuses a language with an environment and/or implementation and/or API.
Ca. 1998-2000, I was writing these things in JavaScript:
*Web browser DOM stuff aka "Dynamic HTML"
*Server-side ASP and NS-SSJS (Remember Netscape? They used to do servers, too...)
*System apps using ScriptEase/JS on *nix and COM/ActiveWhatever/JS on Windows
*Interaction in PDFs and SVG docs
*Extensions for Macromedia (now Adobe) DreamWeaver
*Extensions for Mozilla
We didn't have Ajax or Canvas in those days. We also didn't have smartphones or Justin Bieber.
But we still used JavaScript in lots of places, we still made phone calls, and we still changed the channel or hit the Mute button when MTV started playing crap.
Il n'y a pas de Planet B.
However, it sure would reduce cognitive load to not switch languages between browser and server ends.
I don't know, I don't think having to know several languages is that much of a chore. I kind of prefer languages to be specialized for specific purposes, because you can't be the best at everything. I don't know how much sense it would make to use SQL syntax for geometry shaders, or for asm to be used as a HTML dom manipulation. When you write a language to support everything, it is just as much detail to learn as learning several languages (where 'learn' means have a good understanding of API, objects, methods, etc. and not just a rudimentary comprehension of syntax).
HA! I just wasted some of your bandwidth with a frivolous sig!
This sounds like a MongoDB ad. There's no particular reason that server-side Javascript should use MongoDB. There's "node.js" support for most databases.
"It's effectively impossible to launch a sophisticated Web project without making extensive use of JavaScript and AJAX dynamic loading."
Yeah, that's why my (extensive) web infrastructure has ZERO javascript in it....
Your thin skin doesn't make me a troll
Wake me up when this is over.
none
Until Javascript has a standard foreign function interface, and people being writing bindings to C/C++ libraries, and there exists some sort of packaging system to install these bindings and libraries, Javascript will be severely lacking capabilities present in several other languages.
It seems to me (normal career newb disclaimer here) that node is going to burn less juice than PHP under Apache. Disregarding for a moment my general dislike of php (except the paychecks) and my general dislike of the Drupal/WP/Joomla ... uh ... paradigm my experiences with node/mongo have been very refreshing. Async is a cool way to work with once you get your head around it (my head maybe 90 degrees so far ...) and Mongo / document storage is way more natural for certain kinds of relatively big data issues than mysql (which I have no hatred for)
But back to the top. Hey server guys and gals: Wouldn't node draw less electric, like way less. So if my webbloging socialnetworking ecommercing socialgaming buzzwordcompliant client blows up they'd need less of a web armada ... right? And they'd be helping the environment by not using Wordpress or Drupal.
Physics is like sex: sure, it may give some practical results, but that's not why we do it.
Briefly, I work at a company that produces your stereotypical "web app": a minimal index.html which pulls everything in via JavaScript. We deploy to ~12,000 physically separate production environments every few months. Prior to my current gig, I helped build Node.js daemons / WebSocket functionality in a FTSE 100 company on a site that receives so many millions of hits per-day I can't remember the numbers. TL;DR I'm not just sitting in my bedroom writing Node.js "Hello World!" apps.
All the arguments I've read above have some serious issues:
JavaScript is a shit language: Fuck off.
JavaScript is not strongly-typed: Since when did strongly-typed languages become "better"?
JavaScript is insecure: You're doing it wrong.
Node.js is single-threaded: OK, were you planning on serving clients with a single server instance/process?
A single language client- and server-side offers little to no benefits: Yeah, you're right. Why would I want to a single test suite for my client- and server-side code? Why would I want to (securely) share model definitions between the client- and server-side? Why would I want to optimise one code-base instead of two? Why would I want to debug one language instead of two?
MongoDB is for people who can't/won't learn SQL/the relational model: I'll admit that SQL is not my area of expertise, but my naive understanding is this: in SQL databases, you normalise your data by default until you hit performance issues. In NoSQL databases, you denormalise it by default. The decision on which one to use should depend entirely on the data you want to store.
I could go on, but I'm tired of dissecting your attempts at a debate. For a damn good overview, see this StackOverflow discussion.
Lastly, has anybody considered why JavaScript is becoming a "lingua franca"? Every language since assembly languages has focussed on abstracting stuff away from the programmer when it isn't necessary. When I'm writing a web app, I don't give two hoots whether how big your address space is, what network interface you're using, how big your monitor is, or anything else below the level of the browser. I care about drawing stuff on the screen with minimal effort.
Different problems require different solutions. In some cases, JavaScript all the way through might be a good fit. Most of the time, it won't be.
Great! Now all we need to do is get everyone else to do that (and to switch to IE) and we'll have a competitor to Javascript.
systemd is Roko's Basilisk.
I don't know, I don't think having to know several languages is that much of a chore. I kind of prefer languages to be specialized for specific purposes, because you can't be the best at everything. I don't know how much sense it would make to use SQL syntax for geometry shaders, or for asm to be used as a HTML dom manipulation. When you write a language to support everything, it is just as much detail to learn as learning several languages (where 'learn' means have a good understanding of API, objects, methods, etc. and not just a rudimentary comprehension of syntax).
I work constantly in C, Objective-C, C++, Ruby, bash, and javascript. I have worked in Common Lisp, Pascal, various assemblers, Python, Dylan, various nasty proprietary "4GL" languages, AppleScript, Visual BASIC, C#, Java...
There is no benefit to flipping between high-level scripting languages throughout the day; it is a complete waste of cognitive effort.
I'm sorry, I don't know or care what "full stack" means in this context, but please stop extending the Javascript language to do things it was not supposed to do, and just making it horribly more complex than necessary.
There's the C++/Java people who keep trying to turn Javascript into a class'd OOP language, which it isn't, and should never be.
There's the Media people who can't standardize on an Audio API, let alone an Audio or video container or codec, so web browsers and javascript are left having to bit fiddle
There's the OpenGL games people who keep trying to turn Javascript into a WebGL game platform, which isn't ever going to work. Look at Polycraft, the game basically is only capable of PSX (yes playstation 1) level of graphics, and even that is unable to take advantage of multiple cores, so it's never going to be able to do anything better. WebGL was meant for previewing models, not playing games. If we want to use WebGL for playing games, a higher level API is going to be required, because a low-level API is horribly slow.
Then there's the DRM people who want to protect their media despite there being NO STANDARDIZED VIDEO TO BEGIN WITH.
And of course there's the absolute lack of being able to use multithreading in any shipping browser.
The "web" platform, is not for games, and not for media. That is clear. That has been clear since Flash has been doing these things since Flash 9. The elephant in the room is that both WebGL and Canvas are solutions for a problem they created. Canvas has it's uses, but it's pretty much a non-starter for anything HD, let alone anything more complicated than a super nintendo game level of graphics. Game consoles have a fixed level of performance, games belong on them. Web browsers do not have a fixed level of performance, therefor they are best suited for applications where latency and processing speed only make it take longer to complete a task. Highly responsive games are not going to happen on the "web" platform, and anyone who's developed a flash game can tell you that.
We all need to step away from using web browsers and javascript as a be-all-end-all because really what is the difference between programming against SDL (which can be ported to everything) in C, and the web browser? The SDL game can actually run at native performance, where as the web browser adds no less than three additional layers (The browser, DOM and Javascript) into the mix.
There are games that can be written in javascript, but they largely are of the farmville and P&C Adventure variety.
>>But if you're going to pick a single language to be used by everyone for all purposes, then why pick something kludgy like JavaScript?
>Because it is the only language that is universally supported in browsers. Would be nice were that not the case, but it is the fact that we have to live with.
"Because it is the only language for which there are claims of universal support in browsers."
FTFY
JavaScript is a shit language: Fuck off.
Wow, good argument. BTW, my office mate was at Netscape when Javascript was created. The author of Javascript has since apologized for creating Javascript. In his defense, it was only ever intended to run one line bits of logic inside of a web page. Ideas like functions actually had to be added later as the idea of using Javascript for a general purpose language came after the language was designed, not before. See how this leads to problems?
Javascript isn't and shouldn't be used as a general purpose language, EVER! It has uses but very few in general and they probably all have to do with browsers and DOMs.
JavaScript is not strongly-typed: Since when did strongly-typed languages become "better"?
Um, since math has existed? Compilers double as automated code error checkers. Or maybe you like checking your code's syntax by hand?
JavaScript is insecure: You're doing it wrong.
Javascript forces clients to execute general logic. This is a security issue no matter what. I'm sure you have some solution to this issue, but I assure you that there are ways around your solution (and anyone else's solution).
Node.js is single-threaded: OK, were you planning on serving clients with a single server instance/process?
Javascript is single threaded, this is OK for writing web apps, sometimes. But not always and its a huge hole in a general purpose language.
A single language client- and server-side offers little to no benefits: Yeah, you're right. Why would I want to a single test suite for my client- and server-side code? Why would I want to (securely) share model definitions between the client- and server-side? Why would I want to optimise one code-base instead of two? Why would I want to debug one language instead of two?
You finally make a good point. +1 for you.
MongoDB is for people who can't/won't learn SQL/the relational model: I'll admit that SQL is not my area of expertise, but my naive understanding is this: in SQL databases, you normalise your data by default until you hit performance issues. In NoSQL databases, you denormalise it by default. The decision on which one to use should depend entirely on the data you want to store.
Take it from me, you know NOTHING about data persistence no matter how much you think you do. Relational Algebra is the basic math governing manipulating, querying and storing data as tuples. It governs MongoDB (and other NoSQL tools) too, just that the authors of those systems basically lopped off all the hard parts of the relational algebra and implemented just the easy bits. And they did those parts quite poorly when compared to traditional RDBMSes.
NoSQL was an attempt to re-invent a very complex wheel that 1) already worked, and 2) the often didn't let you do things that were bad ideas (even if you didn't realize they were bad ideas at the time). SQL isn't perfect, but more people know it than HTML and Javascript combined. And the systems that implement SQL have reputations (and a history) of not losing data (well, as long as the hardware works) and allowing very large datasets to be queried. And before someone says something dumb like "Web Scale", Sharded DBs store and query some very large datasets. Only when you have datasets the size of google's do you have to implement your own. And they made BigTable so fast by not implementing things that DBs need but they didn't (like data consistency and joins). It might be nice for a RDBMS to allow you to choose to not use table locks or do other things to make these trade-offs. But RDBMSes evolved in a world where throwing hardware at problems was always a valid strategy and it probably still is and will be into the foreseeabl
"Those that start by burning books, will end by burning men."
HTML that's not XML is SGML.
SGML leads to pain and misery.
Just wait until you have to use an SGML parser for something, much less try to write one.
Il n'y a pas de Planet B.
Couldn't agree more...
I actually thought ``Forth'' the moment I saw the title.
The nice thing with having the same language on client and server is that it helps a lot for code injection...
I think there's a good chance it will. Just remember that Javascript is based on Actionscript, based on Scheme, based on Lisp. It's actually got a a much better pedigree than most people realize. It implements the lambda calculus wherever there is a web browser. That's pretty much exactly what it needs to do to 'win the wars'. Be ubiquitous and support the lambda calculus. Everything else is just syntax.
If you are a true web developer, I hope you don't put your css styles in camelCase. Between, html, xhtml, css, javascript and your backend server language, things will only improve so much for you. I feel like all web developers try to turn everything into C#. In they try to turn everything into C# (or Java before it.)
And you *need* javascript to store cookies, how?
I haven't thoroughly debugged the scripts on Chase.com, but let me offer a few guesses. Only script can store cookies in localStorage or IndexedDB. Only script can generate a keypair that the server and the browser will use for challenges and responses, and only script can respond to the server's challenges.
And all it does is make pages more cluttered
JavaScript lets a web page hide a particular element until the user expresses interest in viewing it
Requiring extra clicks to read content I could've been reading right away, taking my attention off the act of reading and onto the act of finding what silly tab to click.
Are you familiar with the concepts of "information overload" and "progressive disclosure"? Please look them up on DuckDuckGo before proceeding. The gist is that if a document presents far more information at a time than the user is expecting, the user will find it difficult to find the desired information in the document. An alternate model is to present the entire web site as a single document and use the web browser to navigate in that document, but that's the same model that PDF uses for navigation, and a lot of Slashdot users have voiced their hatred of various things about PDF.
Does it now? Have you measured that, down to the extra handshakes?
It doesn't matter. One handshake to start a download of the 4 kilobytes of information that has can changed and one handshake to start a redownload of the entire page are each one handshake. One of them just transfers less data afterward. Besides, HTTP/1.1 allows a web browser to hold a connection open, resulting in fewer TCP handshakes overall. I myself have not measured that down to the extra handshake, but operators of large web applications have. There are white papers on the Web about on how Yahoo! and Google optimized their web applications to require fewer requests.
It already starts out bad with sometimes huge background images and avatars and all sorts of other crap that you're supposed to be interested in
Which would be sent with or without script. In fact, without script, more things would have to be sent and re-sent.
Actionscript is based on Javascript rather than the other way around.
Sure, everyone thinks they know what that better language is. There is no consensus, there never will be, and other browser makers will resist attempts like Dart and NaCl and pNaCl by one vendor to impose a new language or runtime. So realistically, how will it occur? Every web site has been free to send <script type="text/python" src="foo.py"> or <script type="bin/mybytecode_x64" src="foo.llvm"> pages for close to 15 years now, but no one does because it's a complete non-starter to require end-users to install a special browser or hack in support for a new language module.
Meanwhile in the real world JavaScript (+ HTML + CSS + Canvas + SVG + WebGL + audio processing + sensor support + notifications + real-time communications + ...) keeps improving, despite calls to "stop hijacking" it and to "stay off my lawn".
=S