This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| service.use((req, res, next) => { | |
| const now = new Date().getTime() | |
| res.on('response', (e) => { | |
| e.res.setHeader('x-response-time', new Date().getTime() - now) | |
| }) | |
| return next() | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const service = require('restana')({}) | |
| service.get('/hi', (req, res) => { | |
| res.send('Hello World!') | |
| }) | |
| service.start(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fastify = require('fastify')() | |
| fastify.get('/hi', async (request, reply) => { | |
| return 'Hello World!' | |
| }) | |
| fastify.listen(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const service = require('express')({}) | |
| service.get('/hi', (req, res) => { | |
| res.send('Hello World!') | |
| }) | |
| service.listen(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http') | |
| const service = new http.Server() | |
| service.on('request', (req, res) => { | |
| if (req.method === 'GET' && req.url === '/hi') { | |
| res.writeHead(200, { 'Content-Type': 'text/plain' }) | |
| res.end('Hello World!') | |
| } else { | |
| res.statusCode = 404 | |
| res.end() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const nacl = require('tweetnacl') | |
| nacl.util = require('tweetnacl-util') | |
| // reading Alice key pair from secret key | |
| const alice = nacl.box.keyPair.fromSecretKey(/* Uint8Array with 32-byte secret key */) | |
| // reading Bob public key | |
| const bob = {publicKey: /* Uint8Array with 32-byte secret key */} | |
| // const message = ... the message object from Bob | |
| // Alice decrypts message from Bob |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const nacl = require('tweetnacl') | |
| nacl.util = require('tweetnacl-util') | |
| // generating key pairs | |
| const bob = nacl.box.keyPair() | |
| const alice = nacl.box.keyPair() | |
| // generating one time nonce for encryption | |
| const nonce = nacl.randomBytes(24) | |
| // message for Alice |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const nacl = require('tweetnacl') | |
| nacl.util = require('tweetnacl-util') | |
| // generating Bob key pair | |
| const bob = nacl.box.keyPair() | |
| // generating Alice key pair | |
| const alice = nacl.box.keyPair() | |
| // generating one time nonce for encryption | |
| const nonce = nacl.randomBytes(24) |