简体   繁体   English

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

[英]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? node.js可以用作运行服务器端Javascript的通用框架,专门用于Web应用程序,完全与它的非阻塞和异步路由I / O功能无关吗? Specifically I want to know if I can run arbitrary Javascript on the (web) server without using the other node.js functionality. 具体来说,我想知道我是否可以在(web)服务器上运行任意Javascript而不使用其他node.js功能。

Yes, it's possible to use node.js for command-line applications, for example: 是的,可以将node.js用于命令行应用程序,例如:

$ 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. 在节点上构建了许多Web框架。 The most known is Express based on Connect . 最着名的是基于Connect的 Express

Connect takes the familiar concepts of Ruby's Rack and applies it to the asynchronous world of node Connect采用Ruby的Rack熟悉的概念,并将其应用于节点的异步世界

Express: 表达:

High performance, high class web development for Node.js Node.js的高性能,高级Web开发

But I/O - web request for example - depends on node's asynchronous and non-blocking functionality. 但I / O(例如Web请求)取决于节点的异步和非阻塞功能。

In the end, "node.js" is inside a v8 runtime environment, so you can of course execute arbitrary Javascript code. 最后,“node.js”位于v8运行时环境中,因此您当然可以执行任意Javascript代码。 However, due to it's singe-processed design, it may be difficult to run multiple CPU-intensive computations in parallel. 但是,由于采用单处理设计,可能难以并行运行多个CPU密集型计算。 That is not what node.js has been designed for. 这不是node.js的设计目标。

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. 重要的是要理解的是Node是一组I / O绑定(文件,TCP等),它们位于Chrome的V8 JavaScript解释器之上。

You can use Node in two modes: 您可以在两种模式下使用Node:

  1. Execute a known JavaScript file 执行已知的JavaScript文件

    $ node some_script.js $ node some_script.js

  2. Execute in REPL (interactive mode) 在REPL中执行(交互模式)

    $ node $ node

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是“PHP”的运行时环境,例如用于构建服务器端 Web 应用程序的“Javascript”的“Node.js”运行时环境? - What is and where is the runtime environment for 'PHP' like the 'Node.js' runtime environment for 'Javascript' to build server-side web applications? Web套接字和服务器端Javascript的解释(特别关注node.js) - An explanation of web sockets and server-side Javascript (especially focused on node.js) 使用Node.js在服务器端使用AngularJS - AngularJS at server-side with Node.js 获取客户端javascript代码中可用的node.js服务器端对象 - Get node.js server-side object available in client-side javascript code 是否可以在node.js服务器上设置运行(服务器端)的socket.io客户端? - Is it possible to set up a socket.io client running (server-side) on a node.js server? 客户端和服务器端js的Javascript OOP库(node.js) - Javascript OOP library for client and server-side js (node.js) Netscape Enterprise Server和服务器端JavaScript(SSJS)与Node.js - Netscape Enterprise Server and Server-Side JavaScript (SSJS) vs Node.js 括号编辑器和“ Node.js:服务器端Javascript”具有所有处理能力 - Brackets editor and “Node.js: Server-side Javascript” taking all processing power Node.js JavaScript-从外部脚本服务器端调用函数 - Node.js javascript - call function from external script server-side 使用 Adob​​e Dreamweaver 时如何禁用“Node.js:服务器端 JavaScript”的自动启动? - How to disable auto-start of “Node.js: Server-side JavaScript” when using Adobe Dreamweaver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM