Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.js and micro simple web service for running in K8S with draft
const http = require('http')
const { run, send, json } = require('micro')
const PORT = process.env.PORT || 8080
const response = "Hi from MICROservice on K8S draft"
const microHttp = fn => http.createServer((req, res) => run(req, res, fn))
const server = microHttp(async (req, res) => {
const js = await json(req);
const statusCode = 200;
const data = { ...js, response };
send(res, statusCode, data);
})
server.listen(PORT)
console.log(`Listening on https://localhost:${PORT}`)
{
"name": "node",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "node ."
},
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"micro": "^9.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment