Skip to content

Instantly share code, notes, and snippets.

@prettymuchbryce
Last active April 29, 2021 14:50
Show Gist options
  • Save prettymuchbryce/5542020 to your computer and use it in GitHub Desktop.
Save prettymuchbryce/5542020 to your computer and use it in GitHub Desktop.
hello TypeScript & node.js
/// <reference path="./.node-definitions/node.d.ts" />
/**
* See the node.js TypeScript definition needed for this
* example here: https://github.com/borisyankov/DefinitelyTyped
*/
import Http = module('http');
class MyServer {
private header:Object = {'Content-Type': 'text/plain'};
constructor() {
var server:Http.Server = Http.createServer(this.onRequest);
server.listen(3000);
console.log("Server starting..");
}
private onRequest(request:Http.ServerRequest, response:Http.ServerResponse):void {
response.writeHead(200, this.header);
response.end("Hello TypeScript & node.js");
}
}
var myServer = new MyServer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment