window.ENTITIES={'/api/snippets/java/express.js%20-%20run%20server%20using%20http2%20(h2%20or%20h2c)':[{"result":true,"message":null,"batch":{"type":"java","name":"express.js - run server using http2 (h2 or h2c)","items":[{"id":"p5ddRD","type":"java","name":"Express.js - run server using HTTP2 (h2 or h2c)","content":"// Simaple steps:\n//\n// 1. Create project directory and paste `index.js` into.\n//\n// 2. Generate example localhost certificate using:\n// openssl.exe req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost'\n//\n// Source: https://dirask.com/posts/openssl-generate-localhost-pem-certificate-under-Windows-1enOWD\n//\n// 3. Paste generated key.pem and cert.pem files directly into project directory.\n//\n// 4. Install dependencies using:\n// npm install\n//\n// 5. Run application using:\n// node index.js\n//\n// 6. Open in the web browser the following address:\n// https://localhost:8443\n\n\n\n// --------------------------------------------------\n// index.js file:\n// --------------------------------------------------\n\nconst fs = require('fs');\nconst path = require('path');\nconst spdy = require('spdy'); // npm install spdy\nconst express = require('express'); // npm install express\n\nconst credentials = {\n key: fs.readFileSync(path.join(__dirname, 'key.pem'), 'utf8'),\n cert: fs.readFileSync(path.join(__dirname, 'cert.pem'), 'utf8'),\n};\n\nconst app = express();\n\n// ...\n\napp.get('/', (request, response) => {\n response.send('Hello World!');\n});\n\n// ...\n\nconst server = spdy.createServer(credentials, app);\n\nserver.listen(8443, () => console.log('Server started on https://localhost:8443'));\n\n\n// See also:\n//\n// 1. https://dirask.com/snippets/Express-js-run-server-using-HTTP2-H2-1b88wp","source":"","author":{"id":"Ro42dD","name":"Creg","avatar":"1667335677213__Ro42dD__w40px_h40px.jpg","points":9600,"role":"ADMIN"},"creationTime":1700994177000,"updateTime":1701038221000,"removalTime":null},{"id":"1b88wp","type":"java","name":"Express.js - run server using HTTP2 (h2 or h2c)","content":"// Simaple steps:\n//\n// 1. Create project directory and paste `index.js` into.\n//\n// 2. Generate example localhost certificate using:\n// openssl.exe req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost'\n//\n// Source: https://dirask.com/posts/openssl-generate-localhost-pem-certificate-under-Windows-1enOWD\n//\n// 3. Paste generated key.pem and cert.pem files directly into project directory.\n//\n// 4. Install dependencies using:\n// npm install\n//\n// 5. Run application using:\n// node index.js\n//\n// 6. Open in the web browser the following address:\n// https://localhost:8443\n\n\n\n// --------------------------------------------------\n// index.js file:\n// --------------------------------------------------\n\nconst fs = require('fs');\nconst path = require('path');\nconst http2 = require('http2');\nconst express = require('express'); // npm install express\nconst bridge = require('http2-express-bridge'); // npm install http2-express-bridge\n\nconst credentials = {\n key: fs.readFileSync(path.join(__dirname, 'key.pem'), 'utf8'),\n cert: fs.readFileSync(path.join(__dirname, 'cert.pem'), 'utf8'),\n};\n\nconst app = bridge(express);\n\n// ...\n\napp.get('/', (request, response) => {\n response.send('Hello World!');\n});\n\n// ...\n\nconst server = http2.createSecureServer(credentials, app);\n\nserver.listen(8443, () => console.log('Server started on https://localhost:8443'));\n\n\n// See also:\n//\n// 1. https://dirask.com/snippets/Express-js-run-server-using-HTTP2-h2-or-h2c-p5ddRD","source":"","author":{"id":"1DqPj0","name":"LionRanger","avatar":"1629030436845__1DqPj0__w40px_h40px.png","points":461,"role":"BASIC"},"creationTime":1701036752000,"updateTime":1701037544000,"removalTime":null}]}}]};