3

Can node.js be used as a general framework for running server-side Javascript specifically for web applications, totally unrelated to it's non-blocking and asynchrouns I/O functionality? Specifically I want to know if I can run arbitrary Javascript on the (web) server without using the other node.js functionality.

4 Answers 4

5

Yes, it's possible to use node.js for command-line applications, for example:

$ cat hello.js
console.log('Hello world!');
$ node hello.js
Hello world!

It's essentially just like any scripting language in this regard.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I totally left out the most important part of my question! I intended to about using node.js for arbitrary web applications. Is that possible? By the way your answer about command line apps is very helpful too.
3

Yes. There are many web frameworks built on node. The most known is Express based on Connect.

Connect takes the familiar concepts of Ruby's Rack and applies it to the asynchronous world of node

Express:

High performance, high class web development for Node.js

But I/O - web request for example - depends on node's asynchronous and non-blocking functionality.

Comments

1

In the end, "node.js" is inside a v8 runtime environment, so you can of course execute arbitrary Javascript code. However, due to it's singe-processed design, it may be difficult to run multiple CPU-intensive computations in parallel. That is not what node.js has been designed for.

Comments

0

Yes. What is important to understand is that Node is a set of I/O bindings (file, TCP, etc) that layers on top of Chrome's V8 JavaScript interpreter.

You can use Node in two modes:

  1. Execute a known JavaScript file

    $ node some_script.js

  2. Execute in REPL (interactive mode)

    $ node

    var i = 1;
    console.log(i);
    1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.