简体   繁体   中英

Can node.js be used as a framework for running arbitrary server-side Javascript in web applications?

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.

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.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM