6

I have read that Node.js is a server-side javascript enviroment. This has put few thought and tinkers in my mind.

Can we develop a complete data-drivent web application utilizing just JavaScript (along with node.js), HTML5 and CSS? Do we still need to use some server-side scripting language (e.g. C#, PHP)?

In case we still need to use other scripting languages, what is node.js worth for, or useful?

NOTE: Pardon with my knowledge about node.js.

  • 2
    One of the selling points of Node.js is that it replaces some server-side scripting language (like c#, php) so that you only need to know javascript for both the client and server side – WuHoUnited Nov 22 '11 at 13:50
  • 3
    I think Felix's Node.js Convince your Boss Guide has a few decent points ;) – rlemon Nov 22 '11 at 14:01
  • @rlemon , thanks mate, the link had some great points – Pankaj Upadhyay Nov 22 '11 at 14:17
5

Can we develop a complete data-drivent web application utilizing just the javascript(alongwith node.js) , HTML5 and CSS.

Yes, using node.js can mean that the only programming language you use is javascript, throughout the application stack.

In case, we still need to use other scripting language, then what node.js is worth for or useful ?

No need for another scripting language.

Even if you do use other scripting languages node is still useful - its non-blocking nature and fast response may make it ideal for some parts of your application.


Things to keep in mind about node.js:

  • The programming model uses callbacks. A lot. This takes time to get used to.
  • You can pass JSON between client and server and they will both be able to consume it natively.
  • node has no blocking (achieved by using all those callbacks), so responds very fast.
  • Thanks mate...that's what i was looking for....A one language option for all your server and client scripts requirement....BTW if you have worked with it, how does it fare in performance with regard to PHP ??.... I assume everything should be fast if we are dealing in just one language over the server and client – Pankaj Upadhyay Nov 22 '11 at 14:00
  • 1
    @PankajUpadhyay - No personal experience, but what I have read seems to say that performance is very good. But the programming style is... unusual. Lots of callbacks. And being able to transfer data between server and client natively using JSON is a bonus. The fact that you are using the same language has no bearing on speed. – Oded Nov 22 '11 at 14:02
  • @PankajUpadhyay it's trivially faster then PHP. – Raynos Nov 22 '11 at 15:43
  • 1
    PHP and a lot of other scripting languages never had the advantage of Google, Mozilla, and Microsoft competing to make the fastest JIT compiler for it. – Erik Reppen May 31 '13 at 21:27
5

Do not mistake Node.js for a web development framework. It can be used that way, but so can Ruby without Rails. That doesn't mean you should.

Node.js is simply an event-driven library, written in Javascript. That is, it runs a script in a single thread, but using a system of queues and callbacks to free up that thread for other processing whenever it is doing something which takes time but not resources.

This replaces thread-based libraries, which tend to move the processor from thread to thread when they are all trying to work. This kind of context switching is costly so, generally, event-driven will be faster.

There are a couple of caveats to that though. Event-driven paradigms do not run over multiple processors so, if the load is fairly low, a thread-driven paradigm can be faster by sharing its work across cores (this is not an assumption you can make for certain with all frameworks though).

[Edit, ref Raynos's comment] It appears that the above is easily resolved by running a load-balanced cluster of node.js servers -- one for each core.

And code written to use event-driven paradigms must free up the thread whenever it can, otherwise all other requests will queue up behind it, making it considerably slower than a thread-based paradigm. Luckily most of the work there has been done for you and there are plenty of web development frameworks which sit on top of Node.js to make your life easier.

Pick the right one of those for your needs and yes, you will be able to use Javascript throughout your development stack.

  • Node really isn't a "framework". it's a tool, library or environment. The "only one processor" problem is trivially addressed with node --cluster which spawns slaves and puts a single master node balancer in front of it. – Raynos Nov 22 '11 at 15:46
  • @Raynos: I was looking for the word library. It wouldn't come. Will edit. Did not know about --cluster at all though. You learn something new, ay? – pdr Nov 22 '11 at 16:07
  • --cluster is new in 0.6 :) – Raynos Nov 22 '11 at 18:16
1

Can we develop a complete data-drivent web application utilizing just JavaScript

The answer is Yes. And it is starting already.

It is called FULL-STACK-JAVASCRIPT(FSJS).

Job openings are beginning to open for this position as one indicator.

-1

My 2 pence worth, and an attempt to set some “myths” straight. ...longish but ...

The question is rather open-ended , if not ambiguous at best. To compare apples to apples ( and fish that dont fly) , the question should be more specific on the criteria for comparison > eg Which is better, Java or Node.js, as a serverside technology, or for performance , …or for rapid application development?

which is better Java or Node.js :

  • a fair comparison will be on the basis of either being considered as backend/serverside technologies, and both as frameworks ( forget programming languages ). In practice , not all requirements are the same. So, on a specific consideration, it all depends on what one is trying to accomplish. Overall, it is my opinion that Java is a way better technology than Node.js in ALL aspects : functional, performance, maintenance etc.( see more reasons below ) . For complex and enteprise (grade) applications , node js has many many shortfalls . And from a value proposition perspective, java offers much greater return on investment (ROI), in the short , medium and long term.

What is Node.js really good for ?

  • In my opinion node.js is good for simple serverside modules.

  • It is ideal for quickly putting together serverside application prototypes. These can then be migrated to more suitable implementation frameworks such as java, and other data management frameworks ( eg JDBC etc) ….and suitable qualified as : depending on requirements and project budgets .

  • Nodejs. is also ideal for developers/development teams that are well versed in clientside technologies and want to transition to serverside development . This is due to its “simplicity”, lightweight, and above all based on the javascript language. Past this there is a slew of other key serverside design concepts that need to be masters: multi-tasking (see below ), exception handling , event-based architectures to name a few

  • Argument that Node.js is better because its the same technology ( javascript ) for backend as it is for front end.
  • While the idea of the same technology serverside and clientside is true, the argument does not compare apples to apples. Nodejs is primarily (for now ) a serverside framework. Comparison to java should strictly be around its serverside prowess
  • Java has ( always) support for client side technologies just as JSP, and JSTL. And these technologies fair well, if not better than javascript ( no reference to nodejs here ) . The only key factor here is a good grasp of of java.
  • It is my opinion that this argument holds, and is more relevant to web developers well versed on the clientside ,and wanting to transition or work on serverside of things.

Node.js is a Framework , and (Java is not ?)

  • True, node.js is a framework based on javascript. If semantics are important, Javascipt is a scripting language , which in all intents and purposes, is a “programming language”, like java ( see further discussion below )
  • Real truth: Node.js is strictly a framework based on javascript (programming language), and intended for serverside implementations. Java is both a low level programming language, that comes packaged as application/technology-centric frameworks , or libraries, and is applicable to both serverside and clientside implementation
  • Pants on fire(ish) : Java is not a framework , or does not provide frameworks . Java does not provide clientside frameworks
  • Java is a programming language, a low level programming language . A large part of java is provided as modules that are part of a framework . Any software development kit (SDK) , is essentially a development framework. JEE IS a framework, consisting of application libraries built on java ( and other technologies ) , with modules for specific technologies/services/applications. Other examples : Servlets, Transaction Management, JSP and many many more . Any serious implementation in java is essentially based on using the many solid modules ( libraries) and frameworks .
  • So, what is the freaking difference?. Both Node.js and Java are arguably frameworks. Javascript(for nodejs) and java are both programming languages. The difference is that javascript is interpreted while java is compiled. So what ?. A compiled language is more robust , and has wonderful things like type checking, code error checking before code execution. pointers etc. In a more general sense, a scripting language can be considered a higher level language ( that encapsulates a more complex programming language), that in easier to use, but less “detailed”. To this end, javascript engines ( that thing that makes javascript language a reality ) are often implemented using programing languages like java , C or C++ ( depending on the vendor ) . For example one of the best javascript engine, V8 from google, is implemented using C++ (which is a low level programming language . )

node.js is Open source, (and Java is not)

  • truth: node.js, and its base language , javascript are both open source.

  • Pants on fire(ish) : java is not open source

  • Java is open source. Infact is one of the first, arguably the largest ( other than linux, html, and the internet :) ) , and most stable (and valuable) open source project there has been . Java language is based on a GNU General Public License, Java Community Process, both of which are open source licensing . This has been the case from its early days, since 1998. JEE is also open source, under the Java Community Process. Some implementation of java frameworks and libraries may not be open source, but there is a solid open source reference implementation for every java technology , eg GlassFish for JEE technologies.

Java is more verbose ?

  • Truth : Node.js , as a framework is relatively less verbose, compared to java as a language ( and not a framework )

  • pants on Fire(blazing hot!) : java is relatively verbose compared to Node.js. This is comparing a low low level language to a framework ( node.js) which is based on a high-level language ( javascript) that encapsulates a low level language ( eg java , C++). If the comparison is between Node.js ( a framework ) and Java frameworks ( eg jEE), which is the correct thing to do , the argument still many not hold

  • Truth: as programming languages, javascript ( on which Node.js ) is based on can seem to be less verbose than java language . The java language can be more verbose ( a lot of things to declare, and spell out before getting to the cracks of the matter). But arguably it is this verbosity in java that affords its its swiss-knife credentials, and likewise, its the (apparent) brevity, or short-hand nature of javascript that is its Achilles' heel

  • Truth. Java used as a framework is less verbose. For relatively the same amount of code , java frameworks pack more punch in terms of functionality, code reuse etc , compared to Node.js .

  • This is truly subjective. A large part of the “verbosity” of a program( not language ) can be attributed to “coding styles “ and coding standards. The design of the application being coded is also a factor ( single top down functional coding vs Object oriented coding ) As a language , java can be very “compact” if used the right way . On the basis of the amount of code lines vs functionality implemented, one can right a complete enterprise service side application module in JEE ( java ), that has security ( authentication and authorization) , multithreading and concurrency management ), datastore integration, data persistence management, transaction management(+more ) in under 20 lines of code or even less( solid, verified, secure code). This feat is through SIMPLE use of appropriate java libraries ( and frameworks ) . Not sure if this is even feasible in NODE.js (without dedicated effort to make it happen )

  • The argument on verbosity largely depends on the complexity of the project/application being built. For a simple, single function server side application, node.js can string that in a couple of functions and a few lines of code. For a more complex application or one with involved functionality ( which is a main characteristics of serverside applications) the scale tips the other way in a massive swing: java code will be less verbose by several orders of magnitude.

  • There are many many aspects in java that makes it or intended to make it java less verbose . eg us of classes, libraries , Contexts and Dependency Injection ( CDI) , API galore , to name a few.
  • Node.js tends or seems to be less verbose because it is a framework . The same can be said about its s base language, javascript , largely because it is a HIGH-LEVEL SCRIPTING language. And there is a cost to this abstraction ( eg lack of type checking, loose declaration of variable ). It all somes down to the devil one prefers AND the project requirements (time , resources, budget) .

Multi-threading capability

  • Truth : Node.js ( currently ) does not provide native support for multi-threading in the sense of low level execution/processing threads. Java, and its implementations /frameworks, provides native support for multi-threading, and extensively too ( pre-emption, multi-tenancy, synchronous multi-threading, multi-tasking, thread pools etc )

  • Pants on Fire(ish) : lack of multi-threading in Nodejs is a show stopper. Nodejs is built around an event driven architecture , where events are produced and consumed as quickly as possible. There is native support for functional call backs. Depending on the application design, this highlevel functionality can support what could otherwise be done by thread. s

  • For serverside applications, at an application level , what is important is the ability to perform multiple tasks, concurrently :ie multi-tasking. There are several ways to implement multi-tasking . Multi-threading being one of them, and is a natural fit for the task. That said, the concept of “multi -threading “ is is a low level platform aspect. For instance multi-threaded platform such as java , hosted/running on a single core process server ( server with 1 CPU processor core) still supports multi-multi at the application level, mapped to multi-threading at the low level , but in reality , only a single thread can execute at any ontime. On a multi-core machine with sa y 4 cores , the same multi-tasking at application level is supported , and with up to 4 threads can executing simultaneously at any given time. The point is, in most cases, what really matters is the support for mult-tasking, which is not always synonymous with multi-threading.

  • Back to node.js , the real discussion should be on application design and architecture , and more specifically, support for MULTI-TASKING. In general, there is a whole paradigm shift between serverside applications and clientside or standalone applications, more so in terms of design, and process flow. Among other things, server side applications need to run along side other applications( onthe server ), need to be resilient and self contained (not affect the rest o f the server when the application fails or crashes ) , perform robust exception handling ( ie recover from errors, even critical ones ) and need to perform multiple tasks .

  • Just the ability to support multi-tasking is a critical capability for any server side technology . And node.js has this capability, and presented in a very easy to use packaging . This all means that design for sever side applications need to focus more on multi-tasking, and less on just multi-threading. Yes granted, working on a server-side platform that supports multi-threading has its obvious benefits ( enhanced functionality , performance) but that alone does not resolve the need to support multi-tasking at the application level . Any solid application design for server side applications ,AND node.js must be based on multi-tasking through event generation and consumption ( event processing). In node.js , the use of function callbacks, and small event processors (as functions ), with data checkpointing ( saving processing data , in files or data bases) across event processing instances is key.

What else for Node.js vs Java

  • a whole lot more! Think scalability , code management , feature integration , backward, forward compatibility , return on investment , agility, productivity …
  • ,… to cut on “verbosity” of this article , pun intended :), we will leave it at this for now :) whether you agree or not, please shoot the messenger ( Quora) and not the opinions!

Not the answer you're looking for? Browse other questions tagged or ask your own question.