夢想是鎖不住的html
cd ~/Desktop
mkdir node_koa_learningload
cd node_koa_learningload
npm init
sudo npm install koa koa-static
index.jsnode
const serve = require('koa-static'); const Koa = require('koa'); const app = new Koa(); // $ GET /package.json app.use(serve('.')); // $ GET /hello.txt app.use(serve('test/fixtures')); // or use absolute paths app.use(serve(__dirname + '/test/fixtures')); app.listen(3000); console.log('listening on port 3000');
index.htmlgit
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ArthurSlog</title> </head> <body> <h1>The static web server by ArthurSlog</h1> </body> </html>
// $ GET /package.json app.use(serve('.'));
// $ GET /hello.txt app.use(serve('test/fixtures'));
// or use absolute paths app.use(serve(__dirname + '/test/fixtures'));
index.jsgithub
const serve = require('koa-static'); const Koa = require('koa'); const app = new Koa(); // $ GET /package.json app.use(serve('.')); app.listen(3000); console.log('listening on port 3000');
node index.js