How to start Node.js in specific URL?
node server.js & curl 'http://localhost/my_page'
This starts the server in the background, then immediately uses curl
to make an HTTP request.
The server will still be running after this. You can bring it to the foreground (e.g. in order to kill it) with fg
. Alternatively just run the two commands (without &
) in separate terminals (or screen
s).
If the server doesn't start fast enough, just add a delay:
node server.js & sleep 1 ; curl 'http://localhost/my_page'
How to open a browser window from a node-webkit app?
To open a link in the user's default browser, you could use gui.Shell.openExternal("http://website.com")
. Checkout the documentation for gui.Shell.
How to open links in default browser using Electron
You can do this the way you tried using webContents
's class instance methods instead of static functions
const { app, BrowserWindow, shell } = require('electron')
app.once('ready', () => {
const handleRedirect = (e, url) => {
if (url !== e.sender.getURL()) {
e.preventDefault()
shell.openExternal(url)
}
}
const win = new BrowserWindow()
// Instead bare webContents:
win.webContents.on('will-navigate', handleRedirect)
win.loadURL('http://google.com')
})
Related Topics
Is It Safe to Assume Strict Comparison in a JavaScript Switch Statement
Facebook How to Check If User Has Liked Page and Show Content
Detect iPad Users Using Jquery
How to Remove Spaces from a String Using JavaScript
Setting Multiple Attributes for an Element at Once with JavaScript
React Router Doesn't Work in Aws S3 Bucket
How to Stop a JavaScript for Loop
Classical Inheritance VS Prototypal Inheritance in JavaScript
Jquery Function to Get All Unique Elements from an Array
How to Store a JavaScript Function in JSON
Handle Url Fragment Identifier (Anchor) Change Event in JavaScript
How to Break/Exit from a Each() Function in Jquery
Validate That a String Is a Positive Integer
Plain Count Up Timer in JavaScript
Download File from Bytes in JavaScript