# electron-nestjs **Repository Path**: weini123/electron-nestjs ## Basic Information - **Project Name**: electron-nestjs - **Description**: electron和nestjs 集成; vite、vue、ts - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-07-02 - **Last Updated**: 2025-07-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Vite + Electron + Nestjs Template - In the project folder: ```bash # install dependencies pnpm install # run in developer mode npm run dev # build pnpm run build ``` # 前后端通道 1,restful ~~~ http://localhost:3000/user ~~~ 2,ipc通道 ~~~ preload.js import { contextBridge, ipcRenderer } from 'electron' contextBridge.exposeInMainWorld( 'electron', { sendMsg: (msg: string): Promise => ipcRenderer.invoke('msg', msg), onReplyMsg: (cb: (msg: string) => any) => ipcRenderer.on('reply-msg', (e, msg: string) => { cb(msg) }), }, ) ~~~ ~~~vue const { sendMsg: sendMsgToMainProcess, onReplyMsg } = window.electron async function sendMsg() { try { log.value += `[render]: ${msg.value} \n` const data = await sendMsgToMainProcess(msg.value) log.value += `[main]: ${data} \n` } catch (error) { console.error(error) } } onReplyMsg((msg: string) => { log.value += `[main]: ${msg} \n` }) ~~~ ~~~ nestjs @IpcHandle('msg') public handleSendMsg(@Payload() msg: string): Observable { const { webContents } = this.mainWin mainCC.test = msg webContents.send('reply-msg', 'this is msg from webContents.send') return of(`The main process received your message: ${msg} at time: ${this.appService.getTime()}`) } ~~~