how to make nestjs work with electron application
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[*] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
the electron main.ts
import { app, BrowserWindow } from "electron";
import url from "url";
import { join } from "path";
import { spawn } from "child_process";
import { bootstrap } from "./src/server";
// Keep a global reference of the window object, if you don"t, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win!: any;
function createWindow() {
// 创建浏览器窗口。
win = new BrowserWindow({
width: 1300,
height: 900,
minWidth: 1300,
minHeight: 900,
});
// auth?: string;
// hash?: string;
// host?: string;
// hostname?: string;
// href?: string;
// path?: string;
// pathname?: string;
// protocol?: string;
// search?: string;
// slashes?: boolean;
if (process.env.NODE_ENV !== "production") {
// 打开开发者工具
win.webContents.openDevTools();
// 然后加载应用的 index.html。
win.loadURL(url.format({
host: `127.0.0.1:${3000}`,
slashes: true,
protocol: "http",
}));
} else {
win.loadFile(join(__dirname, "/index.html"));
}
// 当 window 被关闭,这个事件会被触发。
win.on("closed", () => {
// 取消引用 window 对象,如果你的应用支持多窗口的话,
// 通常会把多个 window 对象存放在一个数组里面,
// 与此同时,你应该删除相应的元素。
win = null;
});
}
// Electron 会在初始化后并准备
// 创建浏览器窗口时,调用这个函数。
// 部分 API 在 ready 事件触发后才能使用。
app.on("ready", async () => {
createWindow();
await bootstrap();
});
// 当全部窗口关闭时退出。
app.on("window-all-closed", () => {
// 在 macOS 上,除非用户用 Cmd + Q 确定地退出,
// 否则绝大部分应用及其菜单栏会保持激活。
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", async () => {
// 在macOS上,当单击dock图标并且没有其他窗口打开时,
// 通常在应用程序中重新创建一个窗口。
if (win === null) {
createWindow();
await bootstrap();
}
});
// 在这个文件中,你可以续写应用剩下主进程代码。
// 也可以拆分成几个文件,然后用 require 导入。
the nestjs app entry
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { IoAdapter } from "@nestjs/websockets";
import { HttpExceptionFilter } from "@utils/http.exception";
import { Interceptor } from "@utils/interceptor";
export async function bootstrap() {
const app = await NestFactory.create(AppModule);
// app.useWebSocketAdapter(new IoAdapter());
app.setGlobalPrefix("/client/api/v1");
app.useGlobalFilters(new HttpExceptionFilter());
app.useGlobalInterceptors(new Interceptor());
await app.listen(1992);
}
Current behavior
When I exec nestjs inside electron.
like below image
just init database the url can’t init and the server can’t lanuch.
Expected behavior
I hope the nestjs normal.
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
Nest version:core 5.3.10
For Tooling issues:
- Node version: 8.12.0
- Platform: linux
Others:
my application architecture
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
How to run nestjs with electron? - Stack Overflow
a.1) first build your Web Application. b) build your nestjs application and then copy nestjs node_modules plus nestjs dist into your angular ...
Read more >How to make NestJS works with Electron? · Issue #910 - GitHub
To build make possible create an app that can be installed both on server and on desktop. 1
Read more >How to make NestJS run background with Electron - YouTube
Any questions please let comments below, or send me to my email: truongondaihoc@gmail.com.
Read more >nestjs-electron-ipc-transport - npm
Start using nestjs-electron-ipc-transport in your project by running `npm i nestjs-electron-ipc-transport`. There are no other projects in ...
Read more >Building an app with Next.js and Electron - LogRocket Blog
Use Nextron to create a desktop application and features such as new pages, application layouts, new windows, and executable files.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@printjs Actually, the new angular-console electron app uses nestjs for its backing server. You can see that they are starting the nestjs server here on lines 7 and 57. Viola.
I just told you why. Electron isn’t a framework for building server-side apps, but for building cross-platform desktop apps.