-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
33 lines (29 loc) · 879 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const http = require('http');
const fs = require('fs');
const markdown = require( "markdown" ).markdown;
const open = require("open");
const server = http.createServer((req, res) => {
fs.readFile('./hello.md',(err, data)=>{
if(err){
res.statusCode = 500;
console.log('something error!');
}else{
res.statusCode = 200
res.setHeader('Content-Type', 'text/html;charset=UTF-8');
let abc = data.toString();
const alert = `<script>window.print()</script>`;
const css =
`<style>
pre{
font-size: 20px;
font-family: "微軟正黑體";
}
</style>`;
let show = markdown.toHTML(abc)
res.end(css+show+alert);
}
});
});
server.listen(3000, '127.0.0.1', () => {
open('http://127.0.0.1:3000/', 'chrome');
});