如何在 Xampp 本地主机上安装 nodejs
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18136304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install nodejs on Xampp localhost
提问by Kendall ARNEAUD
Been seeing a lot of how to's on how to install nodejs but nothing is at all clear.
已经看到很多关于如何安装 nodejs 的方法,但什么都不清楚。
So I ask...
所以我问...
Can someone provide a step by step installation guide for installing and using nodejs on a xampp server?
有人可以提供在 xampp 服务器上安装和使用 nodejs 的分步安装指南吗?
回答by T.Todua
After searching (source), I have found, that it's easier to install Node.js directly (so, need of XAMP/WAMP):
在搜索(source)后,我发现直接安装 Node.js 更容易(因此,需要 XAMP/WAMP):
1) Install http://nodejs.org/download/
1) 安装http://nodejs.org/download/
2) Create a test file (example) C:\myFolder\test.jsand put this code in that file:
2)创建一个测试文件(示例)C:\myFolder\test.js并将此代码放入该文件中:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
3) Open CMD (COMMAND PROMPT) and execute:
3)打开CMD(COMMAND PROMPT)并执行:
node C:\myFolder\test.js
4) Open this address in your browser: http://127.0.0.1:1337/
4) 在浏览器中打开这个地址: http://127.0.0.1:1337/
回答by Airy
Now It's really easy to install and use Node.js even with Apache if you are using Xampp/Wamp etc. Because unlike old days, now Node.js org has created MSI installer for windows. Below are the steps to install Node.js with Apache. It is assumed that you have already installed xampp
现在,如果您使用 Xampp/Wamp 等,即使使用 Apache 也可以轻松安装和使用 Node.js。因为与过去不同,现在 Node.js 组织已经为 Windows 创建了 MSI 安装程序。以下是使用 Apache 安装 Node.js 的步骤。假设你已经安装了 xampp
Download windows installer of Node.js from it's site http://nodejs.org/click on download. Hit the Node.js website and click the big green Install button. It'll detect your OS and give you the appropriate installer. If for some reason it doesn't, click the downloads button and grab the one you need. Run the installer. That's it, you have installed Node.js and, equally, NPM – Node Package Manager– which lets you add all kinds of great stuff to Node quickly and easily.
从它的站点http://nodejs.org/下载Node.js 的 Windows 安装程序,点击下载。点击 Node.js 网站并单击绿色的大安装按钮。它会检测您的操作系统并为您提供适当的安装程序。如果由于某种原因它没有,请单击下载按钮并获取您需要的那个。运行安装程序。就是这样,您已经安装了 Node.js 和NPM – Node Package Manager– 它可以让您快速轻松地向 Node 添加各种很棒的东西。
Note
笔记
Keep your Apache and Node ports different. Declare Node port other than 80 or 8080 while creating server in Node because these are the default ports of Apache.
保持 Apache 和 Node 端口不同。在 Node 中创建服务器时声明 80 或 8080 以外的 Node 端口,因为这些是 Apache 的默认端口。
May be these Notes may help someone in future.
可能这些笔记将来可能会对某人有所帮助。
1) When Node.js is installed Nodeand NPMbecome available globally. Means that you can create your site anywhere on your hard drive and with command prompt go to your directory like in Windows Command prompt
1) 安装 Node.js 后,Node和NPM将在全球范围内可用。意味着您可以在硬盘驱动器上的任何位置创建站点,并使用命令提示符转到您的目录,就像在 Windows 命令提示符中一样
d:/NodeSite/node server.js
and now you can access it via
现在你可以通过
http://localhost:3000
because your server.js is running with node.
因为您的 server.js 正在运行节点。
2) Similarly, you can install any Node Package like installing Memcached package or Library
2) 同样,您可以安装任何节点包,例如安装 Memcached 包或库
d:/NodeSite/npm install memcached
"NodeSite" is a folder contain your project. You can see that node and npm have become globals.
“NodeSite”是一个包含您的项目的文件夹。你可以看到 node 和 npm 已经变成了全局变量。
回答by user3806549
I never gave a lot of answers on this site. Because most of the time I'm not an expert however. I had the same issue a while back.
我从来没有在这个网站上给出很多答案。因为大多数时候我不是专家。不久前我遇到了同样的问题。
1) You don't really need this XAMPP. Node will create its own http_server so I suggest you just forward calls from XAMPP to the Node app.
1) 你真的不需要这个 XAMPP。Node 将创建自己的 http_server,因此我建议您将来自 XAMPP 的调用转发到 Node 应用程序。
2) a good start would be: nodeguide.com/beginner.html
2)一个好的开始是:nodeguide.com/beginner.html
3) I work with PHPstorm which is very nice for Node.js development.
3) 我使用 PHPstorm,这对于 Node.js 开发来说非常好。
3a) Node.js plugin -> https://www.jetbrains.com/phpstorm/help/installing-updating-and-uninstalling-repository-plugins.html
3a) Node.js 插件 -> https://www.jetbrains.com/phpstorm/help/installing-updating-and-uninstalling-repository-plugins.html
3b) read this: http://blog.jetbrains.com/webstorm/2014/01/getting-started-with-node-js-in-webstorm/
3b)阅读这个:http: //blog.jetbrains.com/webstorm/2014/01/getting-started-with-node-js-in-webstorm/
3c) running: http://blog.jetbrains.com/webstorm/2014/02/running-and-debugging-node-js-application/3d) Test your app. You mighht also need this:
3c) 运行:http: //blog.jetbrains.com/webstorm/2014/02/running-and-debugging-node-js-application/3d) 测试您的应用程序。你可能还需要这个:
4) (MysQl db) https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/
4) (MysQl db) https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/
回答by Kevin Simper
XAMPP and a node.js is two different things, which do not need to work together, nor do they need each other.
XAMPP 和 node.js 是两个不同的东西,它们不需要一起工作,也不需要彼此。
XAMPP consists of Apache, MySQL, PHP and Perl.
XAMPP 由 Apache、MySQL、PHP 和 Perl 组成。
Where node.js is just like PHP or Apache, so an application.
node.js 就像 PHP 或 Apache,所以是一个应用程序。
Node.js can be installed from the website, http://nodejs.orgor via the terminal following these instructions:
Node.js 可以从网站http://nodejs.org或按照以下说明通过终端安装:
回答by Evalds Urtans
It is possible to run NodeJS trough Apache/XAMPP. Great tutorial how to setup httpd.conf / vhosts.conf http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache
可以通过 Apache/XAMPP 运行 NodeJS。很棒的教程如何设置 httpd.conf / vhosts.conf http://thatextramile.be/blog/2012/01/hosting-a-node-js-site-through-apache
<VirtualHost 109.74.199.47:80>
ServerName thatextramile.be
ServerAlias www.thatextramile.be
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
In the end it would be accessible trough port 80 thatextramile.be
最后,它可以通过端口 80 thatextramile.be 访问
回答by Pawel Cioch
If you want to run javascript from apache you can do it as CGI module. It wont be exacly node.js server and performance because Apache is your server, but you can execute node.js like scripts http://www.cgi-node.org/
如果您想从 apache 运行 javascript,您可以将其作为 CGI 模块来执行。它不会完全是 node.js 服务器和性能,因为 Apache 是您的服务器,但您可以像脚本一样执行 node.js http://www.cgi-node.org/
You must add a handler to your apache configuration to handle whatever extension files for example .jss via CGI modlue that essentially calls node(.exe) depndeing if linux or windows. I made it work under Bitnami WAMP
您必须在 apache 配置中添加一个处理程序,以通过 CGI modlue 处理任何扩展文件,例如 .jss,如果 linux 或 windows 基本上调用 node(.exe) depndeing。我让它在 Bitnami WAMP 下工作
回答by Ari4
It is not possible to install NodeJs on Xammp.Because Xammp is is simply a toolwhere Apache,MySql,FileZilla,Tomcat and Mercury server are available. Where you will be able to only configure and use these server.
无法在 Xammp 上安装 NodeJs。因为Xammp 只是一个可以使用Apache、MySql、FileZilla、Tomcat 和 Mercury 服务器的工具。您将只能配置和使用这些服务器。
If you want to install Nodjs on Windows Machine, You will have to install it manually.
如果你想在 Windows 机器上安装 Nodjs,你必须手动安装它。

