0

What does this error below mean?

www-0 (err):     at Function._load (/usr/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
www-0 (err):     at Module.require (module.js:468:17)
www-0 (err):     at require (internal/module.js:20:19)
www-0 (err):     at Object.<anonymous> (/usr/local/chroot/my-express-app/bin/www:63:10)
www-0 (err):     at Module._compile (module.js:541:32)
www-0 (err):     at Object.Module._extensions..js (module.js:550:10)
www-0 (err):     at Module.load (module.js:458:32)
www-0 (err):     at tryModuleLoad (module.js:417:12)
www-0 (err):     at Function.Module._load (module.js:409:3)
www-0 (err):     at Function._load (/usr/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
www-0 (err):     at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:46:21)
www-0 (err):     at Module._compile (module.js:541:32)
www-0 (err):     at Object.Module._extensions..js (module.js:550:10)
www-0 (err):     at Module.load (module.js:458:32)
www-0 (err):     at tryModuleLoad (module.js:417:12)
www-0 (err):     at Function.Module._load (module.js:409:3)
www-0 (err):     at Module.runMain (module.js:575:10)
www-0 (err):     at run (node.js:348:7)
www-0 (err):     at startup (node.js:140:9)
www-0 (err):     at node.js:463:3

I am trying to add certbot generated certs to my express app. Below is my bin/www:

#!/usr/bin/env node

/**
 * Module dependencies.
 */

var app = require('../app');
var debug = require('debug')('mongoose-iot:server');
var http = require('http');

// Add HTTPS support.
// https://www.hacksparrow.com/express-js-https.html
// http://stackoverflow.com/questions/11744975/enabling-https-on-express-js
// http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/
var https = require('https');
var fs = require('fs');

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
 * Get port from environment and store in Express.
 */

var httpsPort = normalizePort(process.env.PORT || '3030');
app.set('port', httpsPort);

/**
 * Create HTTPS server.
 */

// Generate self-signed certificate.
// $ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem
// http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/
// http://stackoverflow.com/questions/30957793/nodejs-apn-bad-password-read
// https://startupnextdoor.com/how-to-obtain-and-renew-ssl-certs-with-lets-encrypt-on-node-js/
// https://groups.google.com/forum/#!topic/node-red/g8cPmNgGnh0
var sslPath = '/etc/letsencrypt/live/example.co.uk/';
var options = {
  key: fs.readFileSync(sslPath + 'privkey.pem'),
  cert: fs.readFileSync(sslPath + 'fullchain.pem')
};

var httpsServer = https.createServer(options, app);
var io = require('socket.io')(httpsServer);

/**
 * Listen on provided port, on all network interfaces.
 */

httpsServer.listen(httpsPort);
httpsServer.on('error', onError);
httpsServer.on('listening', onListening);

/**
 * Normalize a port into a number, string, or false.
 */

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}

/**
 * Event listener for HTTP server "error" event.
 */

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

/**
 * Event listener for HTTP server "listening" event.
 */

function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  debug('Listening on ' + bind);
}

Any ideas?

Run
  • 54,938
  • 169
  • 450
  • 748
  • That error log is missing crucial information (for instance, about what the actual error is). – robertklep Apr 04 '17 at 07:12
  • @robertklep I don't see any other error logs apart from this. – Run Apr 04 '17 at 07:14
  • Try not running your app using `pm2`, but by executing `./bin/www` – robertklep Apr 04 '17 at 07:14
  • @robertklep what is wrong with pm2? – Run Apr 04 '17 at 07:15
  • 1
    It apparently isn't showing the entire error... – robertklep Apr 04 '17 at 07:16
  • @robertklep if I run my app via `./bin/www`, how can I get error log in the future? – Run Apr 04 '17 at 07:16
  • 1
    I'm not saying you can't ever use `pm2`, I'm saying that to debug this issue, don't complicate things by adding `pm2` to the mix. If there's an issue with your app, running it with `./bin/www` may reveal more information. – robertklep Apr 04 '17 at 07:17
  • @robertklep thanks. I have tried to run the app with `./bin/www` and there is no error at all! Odd... – Run Apr 04 '17 at 07:20
  • 1
    In that case, I guess that `pm2` is causing the issues. But without more of an error log, it's very difficult to say what's going on. – robertklep Apr 04 '17 at 07:21
  • @robertklep true! dunno what to do with pm2.... it seems not a good software. helps from them are no good too. – Run Apr 04 '17 at 07:23
  • 1
    why don't you let your server (nginx or apache) handle it? That way you can avoid SSL integration at app level. – Ankit Gomkale Apr 04 '17 at 08:01
  • @AnkitGomkale any guide for doing that? I dont have any server serving 80 port. – Run Apr 04 '17 at 08:38
  • 1
    @teelou I have nginx installed for serving port 80. [This](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04) is the tutorial I'd followed. There is similar tutorial available for Apache as well. Please check them out. – Ankit Gomkale Apr 04 '17 at 14:04
  • Can you please add a error log with node yourserverfile.js – Tolsee Apr 04 '17 at 15:14
  • @Tolsee where can I add it to? and what is the code for this file? – Run Apr 04 '17 at 17:30
  • @AnkitGomkale with nginx, I only managed to get SSL running on port 80 but how can I have it running on 3838 or 3000 port? – Run Apr 05 '17 at 01:04
  • I am telling you to post the error log when running your file with node not pm2. – Tolsee Apr 05 '17 at 02:18
  • 1
    @teelou there seems to be a little confusion here. See, the default port for HTTP is 80 and that for HTTPS is 443. You should not change this. However, you can run your app on any port. You just have to tell nginx to redirect request from port 80 or 443 to the port which you are using for your app (maybe, port 3000). How to do that can be check [here](https://www.digitalocean.com/community/tutorials/understanding-the-nginx-configuration-file-structure-and-configuration-contexts). – Ankit Gomkale Apr 05 '17 at 06:01
  • @AnkitGomkale any examples of this, eg. redirect 80 to 3000? – Run Apr 05 '17 at 09:38
  • @teelou there is no one single example covering all these aspects. You need to do it step by step. **Step 1:** Install NGINX as a backend server by following [this](https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04) tutorial. **Step 2:** Install certbot and make NGINX configuration by following [this](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04). – Ankit Gomkale Apr 05 '17 at 10:09

0 Answers0