启动 Electron App 后自动运行 Node.js 服务器文件 [英] Run Node.js server file automatically after launching Electron App

查看:140
本文介绍了启动 Electron App 后自动运行 Node.js 服务器文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GitHub Electron 使用 Web 技术创建桌面应用程序.

Im using GitHub Electron to create Desktop application with web technologies.

我使用 Node.js 作为服务器,我的问题是我不知道如何在启动电子时运行文件 server.js应用程序.

I'm using Node.js as the server, my problem is that i don't know how to run the file server.js just when launching the electron app.

我想为分发打包我的应用程序,以便我可以在没有命令行的情况下运行服务器 $ node server.js.

I want to package my app for distribution so that i can run the server without the command line $ node server.js.

推荐答案

只需简单地 require 主文件中的 server.js 文件(例如 app.js):

Just simply require the server.js file in your main file (e.g. app.js):

var app = require("app")
  , server = require("./server")
  ;

...

server.js 文件中你可以拥有:

And in the server.js file you can have:

 require("http").createServer(function (req, res) {
     res.end("Hello from server started by Electron app!");
 }).listen(9000)

这篇关于启动 Electron App 后自动运行 Node.js 服务器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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