2

I'm trying to build a desktop application using electron js .I want to integrate express js in my application .when I try to start my application,I'm facing this error

[Main Instruction]
A JavaScript error occured in the browser process

[Content]
Uncaught Exception:
Error: listen EADDRINUSE :::3000
    at Object.exports._errnoException (util.js:814:11)
    at exports._exceptionWithHostPort (util.js:837:20)
    at Server._listen2 (net.js:1214:14)
    at listen (net.js:1250:10)
    at Server.listen (net.js:1340:5)
    at EventEmitter.listen (C:\Users\Kobbi\WebstormProjects\untitled14\node_modules\express\lib\application.js:617:24)
    at Object.<anonymous> (C:\Users\Kobbi\WebstormProjects\untitled14\index.js:17:18)
    at Module._compile (module.js:428:26)
    at Object.Module._extensions..js (module.js:446:10)
    at Module.load (module.js:353:32)'

here is my code:

var BrowserWindow = require('browser-window')
var express = require('express');

var app = express();
app.use(express.static(__dirname));

app.get('/', function (req, res) {
  res.send('Hello World!');
});






var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});




app.on('ready', function() {
  var mainWindow = new BrowserWindow({
    width: 800,
    height: 600
  })
  mainWindow.loadUrl('http://localhost:3000')
})

I would appreciate any help ,thanks in advance

2 Answers 2

3

app.on('ready') ... 'app' is not your express app. this should be electron app.

Example:

var app = require('app');
BrowserWindow = require('browser-window');
express = require('express');
expressApp = express();

May be express use 'app' variable and electron also uses it.

Sign up to request clarification or add additional context in comments.

Comments

0

Normally the EADDRINUSE error means, that your port is already beign used (probably by an instance of your express webserver). Maybe your electron app didn't close properly, and you have to kill to manually to also kill the webserver that is accessing the port.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.