了解node.js的某些方面 [英] Understanding some aspects of node.js

查看:60
本文介绍了了解node.js的某些方面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解node.js的几个方面.我希望有人可以使事情变得更清楚

There are a couple of aspects of node.js I don't quite understand. I hope someone can make things clearer

在安装node.js时,应在哪里存储文件,以便Web浏览器可以显示您的内容?例如,Apache有一个www文件夹.

When you install node.js where do you store your files so that the web browser can display your content? For example Apache have a www folder.

node.js是否可以替换客户端javascript?

Does node.js replace client side javascript?

node.js如何与HTML交互?例如,如果我想将服务器中的数据放入此div元素< div id ="content"></div> 在PHP中,您可以执行以下操作:< div id ="content"><?php echo $ content;?></div>

How does node.js interact with HTML? For example if I wanted to put data from the server into this div element <div id="content"></div> In PHP you could do something like this: <div id="content"><?php echo $content; ?></div>

您会从客户端调用node.js吗?例如:对node.js的Ajax请求以获取数据.

Would you ever call node.js from client side? For example: An Ajax request to node.js to get data.

令我困惑的是,因为它是从服务器运行的,所以我希望可以在浏览器中使用javascript从node.js服务器获取数据.但是,我看到的例子从来没有做过.

Whats confusing me is that because it is run from the server then I expect that I can use javascript on the browser to get data from the node.js server. However, examples I seen this is never done.

预先感谢

推荐答案

在安装node.js时,应在哪里存储文件,以便Web浏览器可以显示您的内容?例如,Apache有一个www文件夹.

When you install node.js where do you store your files so that the web browser can display your content? For example Apache have a www folder.

任何您想要的地方.node.js不提供静态内容,而是运行JavaScript.您可以在启动时告诉它要运行哪个脚本.

Wherever you want. node.js doesn't serve static content, it runs JavaScript. You tell it which script to run when you start it.

您可以编写一些可提供静态内容的JavaScript,但是将其保留在何处取决于您编写的代码.

You could write some JavaScript that serves static content, but where you would keep it depends on the code you wrote.

node.js是否可以替换客户端javascript?

Does node.js replace client side javascript?

仅在任何服务器端编程可替代客户端JavaScript的情况下.

Only in so far as any server side programming replaces client side JavaScript.

在服务器端使用JS的一个优点是,您可以在客户端和服务器上重用库.有关声称专注于此的框架,请参见 Mojito (我没有时间尝试我自己).

One advantage of using JS on the server side is that you can reuse libraries on both the client and the server. See Mojito for a framework that claims to focus on this (I haven't had time to try it myself yet).

例如,如果我想将服务器中的数据放入此div元素< div id ="content"></div> ,在PHP中,您可以执行以下操作:<代码>< div id ="content"><?php echo $ content;?></div>

For example if I wanted to put data from the server into this div element <div id="content"></div> In PHP you could do something like this: <div id="content"><?php echo $content; ?></div>

PHP是具有嵌入式编程语言的模板语言.JavaScript是一种编程语言.通常,您会从JS使用模板语言(例如小胡子).

PHP is a template language with an embedded programming language. JavaScript is a programming language. Typically you would use a template language (e.g. moustache) from your JS.

您会从客户端调用node.js吗?例如:对node.js的Ajax请求以获取数据.

Would you ever call node.js from client side? For example: An Ajax request to node.js to get data.

是的,如果您愿意的话.就像任何其他服务器端编程环境一样.(假设您正在使用节点运行HTTP服务器).

Yes, if you want to. Just like any other server side programming environment. (Assuming you are using node to run an HTTP server).

这篇关于了解node.js的某些方面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆