全栈:静态网址
静态网址
实例:
//静态网址 var http = require('http') var querystring = require('querystring'); var fs = require('fs') var url = require('url') var app = http.createServer((req, res) => { let urlobj = url.parse(req.url) let pathname = urlobj.pathname let path = __dirname + '/src' + pathname fs.readFile(path) if (pathname == '/') { path = 'src/index.html' } fs.readFile(path, (err, data) => { if (!err) { res.end(data) } else { res.end('404') } }) }) app.listen(8080)