开发者

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

开发者 https://www.devze.com 2023-02-04 12:47 出处:网络
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

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 functi开发者_Go百科onality.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号