Last active
January 7, 2019 02:54
-
-
Save MSakamaki/02aa9d9beb70f4e35287ceedf3a48c36 to your computer and use it in GitHub Desktop.
deno.scripts
This file contains 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
{ | |
"compileOnSave": false, | |
"compilerOptions": { | |
"baseUrl": "./", | |
"outDir": "./dist", | |
"sourceMap": true, | |
"declaration": true, | |
"moduleResolution": "node", | |
"emitDecoratorMetadata": true, | |
"experimentalDecorators": true, | |
"target": "es6", | |
"types": [ | |
], | |
"paths": { | |
"http://*": ["../../.deno/deps/http/*"], | |
"https://*": ["../../.deno/deps/https/*"] | |
}, | |
"typeRoots": [ | |
// deno --types > types/deno.d.ts | |
"types" | |
], | |
"lib": [ | |
] | |
} | |
} |
This file contains 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
import { args, readDir } from "deno"; | |
import { parse } from "https://deno.land/x/flags/index.ts"; | |
const argPath = parse(args)._[1] as string; | |
const path = argPath.startsWith('/') ? argPath : `./${argPath}`; | |
(async () => { | |
const files = await readDir(path); | |
files | |
.sort((a, b) => (a.isFile() === b.isFile()) ? 0 : a.isFile() ? 1 : -1) | |
.forEach(file => { | |
console.log(file.isFile() ? 'F:' : 'D:', file.name); | |
}); | |
})(); |
This file contains 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
import { serve } from "https://deno.land/x/net/http.ts"; | |
const s = serve("0.0.0.0:8000"); | |
async function main() { | |
for await (const req of s) { | |
req.respond({ body: new TextEncoder().encode("Hello World\n") }); | |
} | |
} | |
main(); |
This file contains 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
import { listen, copy } from "deno"; | |
(async () => { | |
const addr = "0.0.0.0:8080"; | |
const listener = listen("tcp", addr); | |
console.log("listening on", addr); | |
while (true) { | |
const conn = await listener.accept(); | |
copy(conn, conn); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment