What is "server" in server-side javascript like NodeJS?

34,812

Solution 1

No, it isn't.

Server generally has two meanings:

  1. A piece of software that listens for network requests and then responds to them
  2. A computer running such a piece of software

A Node.JS server can be either of those.

In web programming, a Node.JS server takes the place of Perl, Python, Ruby, PHP, Scala, etc. (And like those other languages, Node.JS lets you use JavaScript for non-server and non-web purposes).

Generally the server itself is run directly from Node (e.g. with this library) rather than being embedded in another server like Apache (as is most common for PHP).

A browser doesn't need to be involved at all. If one is, then it will probably be one acting as a client and making a request to the server. That said, tools like PhantomJS can allow a browser to be driven from Node (and other programming languages).

Solution 2

From here:

Server-side JavaScript (SSJS) refers to JavaScript that runs on server-side and is therefore not downloaded to the browser. This term is used to differentiate it from regular JavaScript, which is predominantly used on the client-side (also referred to as client-side JavaScript or CSJS for short).

Solution 3

NodeJS runs on the V8 JavaScript Engine which does not have to be in a browser. It just executes JS. It does not depend on what you do with it. In the case of a NodeJS server, it listens to HTTP requests and is therefore a server.

Solution 4

enter image description here

node.js is single threaded process and run event loops

Share:
34,812
Divs
Author by

Divs

Updated on December 30, 2020

Comments

  • Divs
    Divs over 3 years

    Is it not a Javascript engine hosted by the browser on the client machine itself?

  • Quentin
    Quentin over 8 years
    This seems to be a random fact about Node.JS and otherwise completely unrelated to the question that was asked.
  • CherryNerd
    CherryNerd over 8 years
    I recently used Node.js to extract data from some txt files and post them to a MSSQL server (school assignment), and that's ALL it does. So it indeed isn't an HTTP server by default :)
  • Divs
    Divs over 8 years
    @Quentin. Thanks a lot. Now let's say if I have a web application; that uses NodeJS; is hosted in Tomcat, webLogic etc, then where and how that server comes into play?
  • Quentin
    Quentin over 8 years
    As I said, Node.JS is the server. You use it to run a server side JavaScript program instead of using Tomcat or WebLogic to run a server side Java program (or you play juggling games involving multiple servers and multiple server side languages (for different bits of a site) which might require some tricky passing of data between them)
  • Divs
    Divs over 8 years
    @Quentin. So if I use NodeJS can't I have a single .war file containing the UI along with Server-Side java code? If not then 2 deployables will be created?
  • Quentin
    Quentin over 8 years
    Since JavaScript and Java are completely separate languages (with about as much in common as cars and carpets): no you can't use Node to run a Java program.
  • Divs
    Divs over 8 years
    @Quentin. :-) Indeed, that was not the question. I'm just wondering if it is possible to host multiple different deployments with the same domain name so that when UI (NodeJS Deployment) makes a AJAX call to the Server side backend (Tomcat Deployment), it doesn't run into CORS issue.
  • Quentin
    Quentin over 8 years
    You can't have multiple servers listening on the same port. You can have one server proxy a request to another.