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

StackOverflow https://stackoverflow.com/questions/4649692

문제

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. 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.

다른 팁

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.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top