0.0.2 • Published 6 months ago
serve.node v0.0.2
Node.serve()
This is a demo project that attempts to mirror partial Deno.serve()
api in Node.js.
I don't recommend this for production. It is fine to use for development and playing around.
If you are interested in making this project production ready, please let me know.
Installation
$ npm i serve.node
Documentation
This project was created by taking references from Deno.serve (v1.38.1) api documentation. Therefore, things should work similarly.
Example
Run the following code:
import { Node, Response } from 'serve.node';
Node.serve(() => new Response('Hello World'));
It spins up an http server on port 8000
by default.
You can then make a request to the server:
const res = await fetch('http://localhost:8000');
const body = await res.text();
console.log(body); // 'Hello World'