Skip to content

Instantly share code, notes, and snippets.

@ma-he-sh
Created June 19, 2017 00:08
Show Gist options
  • Save ma-he-sh/81c75485fc6087fab5c7d4ec3a34b0ed to your computer and use it in GitHub Desktop.
Save ma-he-sh/81c75485fc6087fab5c7d4ec3a34b0ed to your computer and use it in GitHub Desktop.
ElectronExpressNodeJS
const server = require('./server');
const electron = require('electron');
// Module to control application life.
const {
app
} = electron;
// Module to create native browser window.
const {
BrowserWindow
} = electron;
// 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;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 960,
height: 600,
title: "<APPNAME>",
icon: 'assets/img/logo.png', //custom logo location
resizable: false
});
win.setMenuBarVisibility(false);
// and load the index.html of the app.
//win.loadURL(`file://${__dirname}/main.html`);
win.loadURL(`http://localhost:5555/`); <== SET THE URL TO PORT
// Open the DevTools.
//win.webContents.openDevTools();
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
doctype html
html
head
title=title
link(rel='stylesheet', href='/style/app.css')
body
| Node V:
script.
document.write(process.versions.node);
br
| Chrome V:
script.
document.write(process.versions.chrome);
br
| Electron V:
script.
document.write(process.versions.electron);
.wrapper
| < ElectronExpressNodeJS >
{
"name": "electronode",
"version": "1.0.0",
"description": "testing electron and node",
"main": "index.js",
"scripts": {
"server": "node server.js",
"start": "electron .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "your_name",
"license": "ISC",
"devDependencies": {
"electron": "^1.6.2"
},
"dependencies": {
"express": "^4.15.2",
"jquery": "^3.2.0",
"pug": "^2.0.0-beta11"
}
}
module.exports = function(app, router, path) {
router.use(function(req, res, next) {
console.log("/" + req.method);
});
app.get("/", function(req, res) {
res.render("index", {
title: "app_test"
});
});
app.use("/", router);
app.use("/", function(req, res) {
res.sendFile(path + "404.html");
});
}
var express = require("express"),
$ = require("jquery"),
app = express(),
router = express.Router(),
path = __dirname + "/views/"
app.set("view engine", "pug")
app.use(express.static("public"));
require('./app/routes.js')(app, router, path)
app.listen(process.env.PORT || 5555);
console.log("SERVER ON: 5555");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment