简体   繁体   中英

The process of Nodejs running a js file

我是Nodejs世界的新手,我有一些问题。为什么当我使用命令node xxx.js时,节点服务不需要启动而apache服务需要启动,它可以给我结果,节点如何做到这一点?此过程的步骤是什么。

node is a program that contains the Javascript interpreter. To run a script file, you run node and pass it the script you want to run on command line. It initializes itself, then loads and runs the desired script.

node is more generic than Apache. It is not, by itself, a server of any kind. If you want a node.js app to be a server, you have to start a server yourself in your Javascript code.

Apache is a web server. When you start it, it starts a web server and then you can run things in the context of that web server. Apache does not contain it's own language interpreter like node does. It can run other types of code like PHP, but you have to supply it with a PHP interpreter in order for it to do that. node, on the other hand, has a Javascript interpreter built in.

While node can be used to create a web server by writing a Javascript script that creates and starts a web server, node is more generic than Apache. node can be used for all sorts of non-web server types of things. For example, I have a nodejs script on my computer that runs automatically each night that cleans up a bunch of automatic backup files on my disk by aging them (files older than a week are deleted). That isn't something you would do with Apache.

So, while there's some functionality overlap only because you can create a web server with node.js, node and Apache are fundamentally different types of tools.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM