0

I am trying to create a HTTPS server with express and typescript and here is my code, for some reason the https.createserver seems to never be working and i get this error:

UnhandledPromiseRejectionWarning: Error: error:0909006C:PEM routines:get_name:no start line

but i am new in this and i have found 0 answers online.

On my App.ts in the contructor i have:

this.express= express();
const key = fs.readFileSync('/home/user/private.key');
const cert = fs.readFileSync('/home/user/file.csr');
this.middlewares();
this.routes();
this.app = https.createServer({ key, cert }, this.express);

And the function listen that initializes the app:

listen() {
    this.app.listen(3000);
    console.log('Server on port', 3000);
}

On my index.ts

import { App } from './app'
import { connect } from './database'

function main() {
    const app = new App(4001);
    app.listen();
}

main();
  • Why are you assigning `this.app` in two different places. Something is definitely not right about that. – jfriend00 Feb 24 '21 at 01:56
  • Your particular error message makes it appear that either your key or cert file is not valid. – jfriend00 Feb 24 '21 at 15:15
  • Discussion of something similar here: https://stackoverflow.com/questions/22584268/node-js-https-pem-error-routinespem-read-biono-start-line – jfriend00 Feb 24 '21 at 15:19
  • i am using a dreamhost server for the app and the crs keys where created by them, maybe i need somekind of root privileges? the next message is the error i receive running the app – Rodrigo Villarroel Feb 24 '21 at 20:03
  • (node:2131) UnhandledPromiseRejectionWarning: Error: error:0909006C:PEM routines :get_name:no start line at Object.createSecureContext (_tls_common.js:129:17) at Server.setSecureContext (_tls_wrap.js:1323:27) at Server (_tls_wrap.js:1181:8) at new Server (https.js:66:14) at Object.createServer (https.js:91:10) – Rodrigo Villarroel Feb 24 '21 at 20:03
  • If you read the link I mentioned in my prior comment, there are several things in there to try. – jfriend00 Feb 24 '21 at 21:31

0 Answers0