Node.js 可以用作在 Web 应用程序中运行任意服务器端 Javascript 的框架吗?

发布于 2024-10-11 00:06:01 字数 136 浏览 0 评论 0 原文

Node.js 是否可以用作专门针对 Web 应用程序运行服务器端 Javascript 的通用框架,而与它的非阻塞和异步 I/O 功能完全无关?具体来说,我想知道是否可以在(网络)服务器上运行任意 Javascript,而不使用其他 node.js 功能。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枉心 2024-10-18 00:06:01

是的,可以将 Node.js 用于命令行应用程序,例如:

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

在这方面,它本质上就像任何脚本语言一样。

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.

辞慾 2024-10-18 00:06:01

是的。有许多基于 Node 构建的 Web 框架。最著名的是基于 Express “nofollow">连接。

Connect 采用了熟悉的概念
Ruby 的 Rack 并将其应用到
节点的异步世界

高性能、高级网络
Node.js 开发

但是 I/O(例如 Web 请求)取决于节点的异步和非阻塞功能。

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.

今天小雨转甜 2024-10-18 00:06:01

最后,“node.js”位于 v8 运行时环境中,因此您当然可以执行任意 Javascript 代码。然而,由于它是单处理设计,并行运行多个 CPU 密集型计算可能会很困难。这不是 Node.js 的设计目的。

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.

鹊巢 2024-10-18 00:06:01

是的。需要了解的重要一点是,Node 是一组 I/O 绑定(文件、TCP 等),位于 Chrome 的 V8 JavaScript 解释器之上。

您可以通过两种模式使用 Node:

  1. 执行已知的 JavaScript 文件

    $ 节点 some_script.js

  2. 以 REPL(交互模式)执行

    $节点

    <块引用>

    var i = 1;
    控制台.log(i);
    1

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文