10 ms·
JavaScript: It’s Not Just for Browsers Any More
- erlanger 17y agoThis is a couple months late but nails it. NodeJS was the spark to the powderkeg. > During development, one small, yet important, feature that Node lacks is the > ability to auto-restart when a change is made to the server’s source code. Hm...sounds like a good application for Node's file-watching capability, so I don't see why this needs to be built-in. Start your app indirectly with a script that monitors the source files.
- sabat 17y agoStrangely enough, Netscape Corporation once marketed javascript as a lightweight server-side language. IIRC the browser-side javascript thing was an afterthought.
- btilly 17y agoYou are right that Netscape used JavaScript as a lightweight server-side language. However my memory from the times is that JavaScript was invented for the browser and then ported to the server.
- rapind 17y agoI think it was called LiveScript. I'm pretty sure it came along after JavaScript as part of Netscape enterprise server or something (kind of like a coldfusion)
- btilly 17y agoLiveScript is what they called JavaScript before the Sun deal involving Java. See http://en.wikipedia.org/wiki/JavaScript#History http://en.wikipedia.org/wiki/JavaScript#History for more.
- asolove 17y agoHot code loading in NodeJS has been implemented many times, see e.g.: http://romeda.org/blog/2010/01/hot-code-loading-in-nodejs.html http://romeda.org/blog/2010/01/hot-code-loading-in-nodejs.ht...
- hugs 17y agoThanks for the link. I think, though, auto-restart is a nice little feature that's important enough that it should be baked-in by default. I just take it for granted that's it already there in other frameworks.
- Ygor 17y agoWhy do we want javascript on the server side, when we already have so many other options? I'm not trying to imply something against this aproach, this really is a question.
- IgorPartola 17y agoIt's a nice clean language that fits the event-driven paradigm better than most. When every function is an automatic closure, things are much easier.
- Periodic 17y agoI still remember when Javascript was a fairly ugly language that felt like the PHP of client-side programming. I revisited Javascript a few years ago and I was pleasantly surprised. It's come a long way, and it does make event-based programming easy.
- jerf 17y agoI'm really at a loss as to how people seem to just swallow this claim without question. What's so special about Javascript's closure support vs Perl, Python, Ruby, PHP, Lua, C#, Lisp, Erlang, or ${all other functional languages}? What's Node.js got over Twisted, POE, EventMachine, or every single thing ever written in Erlang? Most languages used in web development have closures. A large number of them have event-based frameworks. I found quite a few other candidates poking around in the other languages but lacked the skills or time to evaluate whether they were also structured like Node.js. I don't mind the existence of Node.js, but the people claiming it's "better than most" make me wonder if they've ever used the "most" they claim it's better than. Erlang in particular. That's something that's "better at the event-driven paradigm than most". Javascript has nothing on Erlang, Javascript's just another C-derived manually-chop-your-code-up-to-work-with-callbacks monstrosity by comparison. Edit: No, if I were going to pitch Node.js, I would pitch it as "Use the same language on both the client and the server; it's adequate on the client, it's adequate on the server." OK, "adequate" isn't the best pitch but it's honest. The stupidest thing about web development today is needing to know three languages (HTML + browser quirks counts as roughly as complex as a language, client-side JS, server side not-Javascript language) just to get your foot in the door. Having the same language on client and server will probably provide some interesting capabilities, such as the thing mentioned in another comment where your comment formatting code can be run in either place (show on the client exactly what they'll get if they submit, run on the server to validate it), or validation code that is guaranteed identical on both client and server, or several other interesting things I can imagine where you can play games with exactly where something is run. Server-side Javascript just shouldn't be pitched as a "uniquely capable" language in a field full of PHP, Perl, Python, and Ruby... "uniquely capable" is Erlang or a the Seaside framework, not Yet Another (Dynamic) Algol Variant.
- voodootikigod 17y agoJSConf FTW!
- matthijs 17y agoWe're using node for increasingly more projects. It's much easier to create rather complex projects that would take way more time to create when we'd use other languages. For example a simple comet style notification system can be created less than 100 lines of code.
- scotty79 17y agoIf I have: do_thing_A_and_after_that_call(function() { do_thing_B_and_after_that_call(something); } do_thing_C_and_after_that_call(function() { do_thing_D_and_after_that_call(something); } what should I do to execute some E after both B and D is finished? I think that non-blocking effectively means introducing easy syntax for parallel execution while complicating syntax for sequential execution. I think parallel and sequential execution should be easy: on T1 and T2 do E where T1 = (A; B), T2 = (C; D)
- Periodic 17y agoIf A, B, C, and D truly are asynchronous then I believe you're going to need condition variables and (at a lower level) locks. I agree that such syntax should be baked in and handled at a lower level. If you can guarantee that a given variable can only be modified by one process at a time, it is easy to do something to take care of this for individual processes, and wouldn't be hard to generalize. (note, I was last using prototype.js, and my javascript is a bit rusty) wait_list = []; function wait_for(entry) { wait_list.push(entry); }; function done(entry) { wait_list.splice(wait_list.indexOf(entry), 1); if (wait_list.length == 0) { do_C(); } }; function do_A () { wait_for("A"); // do stuff done("A"); }; function do_B () { wait_for("B"); // do stuff done("B"); }; function do_C () { // Stuff that comes after A and B };
- rictic 17y agoNope, no locks needed in Node. This is one of the little joys of javascript: no threading at all. None. With Web Workers you can have processes, but there isn't shared state; everything is done through message passing. All parallelism is cooperative in javascript, meaning that you don't have to worry about control flow switching out from under you at arbitrary points, just when you explicitly yield it by returning from an event handler or from the top level of your program. Finally, to answer the grandparent question, the easiest answer is a promise group. A promise group is basically a promise that emits a success event once all of its child promises have emitted success events. There are a few implementations floating around, though it's just a handful of lines of code to write and makes for a good exercise. So assuming that A and B are rewritten to return promises (or wrapped, I believe that isaacs has a library which will wrap functions which take a callback to return a promise instead), you can do the following: var promise_a = do_A(); promise_a.onSuccess(do_C); var promise_b = do_B(); promise_b.onSuccess(do_D); var promise_group = new PromiseGroup([promise_a, promise_b]); promise_group.onSuccess(do_E);
- fizx 17y agonode.js + coffeescript is the new sexy! It's going to kill my weekend :)
- hugs 17y agoAgreed! (It's already killed a few weekends for me. :-) CoffeeScript has "Most Favored Executable" status in my terminal window these days. On a related side-note... here's the "Hello World" Node.js web server ported to CoffeeScript: http://github.com/jashkenas/coffee-script/blob/master/examples/web_server.coffee http://github.com/jashkenas/coffee-script/blob/master/exampl...
- zokier 17y agoOpenJS-project <http://www.openjs.org/> http://www.openjs.org/> might be of interest to HN peeps too.
- 27182818284 17y agoI have to thank jQuery. Honestly, before jQuery I didn't give Javascript the time of day let alone imagine non-browser uses for it. I have coworkers that are in the same boat; It makes me wonder how many people gave JS a second chance primarily because of jQuery. edit: It also makes me wonder how many people would give lisp, basic, and etc a second chance if those languages had the equivalent of "Wow" that jQuery provided to JS for me and others.
- meilin 17y agoIn <a href="http://www.heyugg.com/ugg-bailey-button-boots-c-1.html><strong>Australia http://www.heyugg.com/ugg-bailey-button-boots-c-1.html>&... boots</strong></a> you will not only get the highest quality products, but highly competitive prices and excellent customer service. If you can not find what you are looking for, or have any questions about our products, please visit our or contact us for more information. Children and <a href="http://www.heyugg.com/ugg-erin-baby-bootie-c-18.html><strong>infants http://www.heyugg.com/ugg-erin-baby-bootie-c-18.html>... boots</strong></a> are also available. As well as <a href="http://www.heyugg.com/ugg-coquette-slippers-c-16.html><strong>ugg http://www.heyugg.com/ugg-coquette-slippers-c-16.html>&#... slippers</strong></a> and Moccassins. In line with our footwear products, we also provide high-quality cashmere shawl, it is incredibly warm sheepskin jacket. Do not forget to visit our special programs page and to seize their a bargain of <a href="http://www.heyugg.com/ugg-erin-baby-bootie-c-18.html><strong>UGG http://www.heyugg.com/ugg-erin-baby-bootie-c-18.html>... boots</strong></a>!妖
- garply 17y agoSecurity issues aside, I'd be more interested in a browser that supported a more powerful javascript than another language I can run on my server.
- scotty79 17y agoHow do you break Node.js? And if you break it how much it is broken? With mod_php even if you kill or freeze single apache process your app is still up and running for other users. What happens if Node.js crashes or hoards resources?
- simonw 17y agoOff the top of my head: run several Node instances (one per core would maximise potential performance) and load balance between them. Have the load balancer / some other monitoring script periodically check each instance to see if it's hung and remove from load balancer, kill and restart it when that happens.
- mark_l_watson 17y agoLast night I watched most of Ryan Dahl's 1 hour video on Node, built it, and played with a few examples. I must admit that I like it much more than I thought that I would. The video is good (but too long) for understanding the motivation of event oriented processing, but if you are short on time, just spending a few minutes building Node and running some examples is informative.