Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and how do you use server side JavaScript? [closed]

Occasionally I search for some JavaScript help and I come upon the term "Server-side JavaScript". When would you use JavaScript server-side? And how?

My experiences of JavaScript have been in the browser. Is there a compiled version of JS?

like image 380
Johnno Nolan Avatar asked Jan 19 '09 21:01

Johnno Nolan


People also ask

What is the use of server side JavaScript?

Server-Side JavaScript is the use of the JavaScript language on servers. You know, those computers that are always on (and maybe online) running stuff, doing all kinds of work. Nowadays many of them have software, web servers, command-line applications, and other services that are written in JavaScript.

Can JavaScript be used for client-side or server-side?

JavaScript is an important client-side scripting language and widely used in dynamic websites. The script can be embedded within the HTML or stored in an external file.

Can JavaScript be executed on the server end?

Javascript is a client-side programming language and all code is interpreted at runtime by the browser on the client's machine. So the short answer is no. For server-side code, use a server-side programming language such as PHP, ASP.NET or ColdFusion. Server side JavaScript was introduced by Netscape in 1994.


2 Answers

It's not AJAX, unless people are using the term improperly. As its name suggests, SSJS is JavaScript that runs on the server, interpreted by a standalone (i.e., browser-independent) JavaScript engine, like SpiderMonkey.

Why bother? Well, one area I currently see it underutilized in is in data validation. With SSJS you write one piece of code that then gets used on both the server and the client. Thus you get immediate user feedback from the client-side JS that will automatically match the data checking taking place on the server.

like image 149
Kev Avatar answered Oct 15 '22 08:10

Kev


There's the project Phobos, which is a server side JavaScript framework.

Back In The Day, the Netscape web server offered server-side java script as well.

In both of these cases, JavaScript is used just like you'd use any language on the server. Typically to handle HTTP requests and generate content.

Rhino, which is Mozilla's JavaScript system for Java, compiles JavaScript in to Java byte codes, which the JVM can choose to JIT. Other systems use other means for executing java script, even to the point that some are JIT compiling their java script internal codes.

I foresee that there will be more and more JavaScript on the server. When you're writing "thick" applications in JavaScript on the client, then you may as well be able to write your logic in JavaScript on the server in order to not have to make the cognitive leaps from one language to another. The environments will be different, but much of your code and knowledge will be shareable.

Finally, JavaScript is probably the singular language that has the most money pointing at it right now in terms of implementations. From Apple, Mozilla, Google, and even Microsoft as well as the efforts to make it an even more advanced language (i.e. basically a Scheme with Algol syntax sans macros).

Most of those implementation are buried in the browser, but that's not to say that there's no value on the server side as well.

The tooling is the biggest place where JavaScript is lacking, especially on the server side, but if you consider something like Phobos, where you can debug your server side JavaScript in the IDE, that's a great advancement.

Personally, I'm tossing JavaScript around in my applications like white paint. It offers cheap extensibility for very little cost and is a great enabler.

like image 44
Will Hartung Avatar answered Oct 15 '22 08:10

Will Hartung