如何设置node.js开发环境/服务器(Ubuntu 11.04)

发布于 2024-12-01 20:40:16 字数 362 浏览 2 评论 0原文

我正在尝试为node.js建立一个开发环境。我起初认为它需要类似于传统的“localhost”服务器方法。但我发现自己不知所措。我设法从终端启动了一个 node.js hello world 应用程序。这看起来没什么大不了的——从控制台启动应用程序并不难。但是,经过一些调整后,我发现更改不会立即显示在浏览器中 - 您需要再次“节点[appName]”它才能运行。

所以,我的问题是: 是否有关于如何在本地计算机上创建更“传统”的开发服务器的软件或教程?除了端口监听设置、各种配置、根目录等(XAMMP、BitNami 甚至预打包的 Ubuntu LAMP 等堆栈中常见的东西)。由于我是 node.js 的新手,我什至无法确定我是否在 google 上搜索正确的内容。

谢谢。

I am trying to set up a development environment for node.js. I assumed at first that it requires something similar to the traditional, "localhost" server approach. But I found myself at a loss. I managed to start a node.js hello world app from the terminal. Which doesn't looked like a big deal - having to start an app from the console isn't that hard. But, after some tweaking, I found out that the changes aren't shown in the browser immediately - you need to "node [appName here]" it again to run.

So, my question is:
Is there a software or a tutorial on how to create a more "traditional" development server on your local machine? Along with port listening setup, various configurations, root directories etc (things that are regular in stacks like XAMMP, BitNami or even the prepackaged Ubuntu LAMP). Since I'm new at node.js, I can't really be sure I'm even searching for the right things on google.

Thanks.

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

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

发布评论

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

评论(2

二手情话 2024-12-08 20:40:16

看看:
https://github.com/remy/nodemon

它允许你做 - nodemon app.js
如果发生故障,服务器将自动重新启动。

Take a look at :
https://github.com/remy/nodemon

it'll allow you to do - nodemon app.js
and the server will restart automatically in case of failure.

千里故人稀 2024-12-08 20:40:16

为此,我在 NodeJS 中构建了一个相对较小的工具,它允许我启动/停止/重新启动 NodeJS 子进程(其中包含实际的服务器)并查看/更改应用程序的配置选项和构建/版本,并提供管理选项不同的 TCP 端口。它还监视所述子进程,以便在出现错误时自动重新生成它(并且在尝试失败后停止尝试并与我联系)。

虽然我被禁止共享源代码,但这需要(内置)child_process 模块,该模块有一个 spawn 方法,它返回一个我猜想的子进程,其中包含一个pid(进程ID),您可以将其与kill方法一起使用来杀死所述子进程。您还可以使用 SIGINT 在子应用程序中捕获它,而不是杀死它,以首先清理一些内容,然后退出。这相对容易做到。

一些关于此的不错的阅读材料。

To do this I built a relatively small tool in NodeJS that allows me to start/stop/restart a NodeJS child process (which contains the actual server) and see/change configuration option and builds/versions of the application, with admin options available on a different tcp port. It also monitors said child process to automatically respawn it if there was a error (and after x failed attempts stops trying and contacts me).

While I'm prohibited from sharing source code, this requires the (built-in) child_process module, which has a spawn method that returns a child process I guess, which contains a pid (process id) which you can use with the kill method to kill said child process. Instead of killing it you could also work with SIGINT an catch it within your child application to first clean up some stuff and then exit. It's relatively easy to do.

Some nice reading material regarding this.

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