使用node写一个简单的页面操作
let http = require('http'); let urlStr = require('url'); let fs = require('fs'); let path = require('path'); http.createServer((req, res) => { const url = req.url; let pname = urlStr.parse(url, true).pathname; function name() { if (pname !== '/') { return path.extname(pname); } } if (pname === '/') { pname = '/index.html'; } console.log(pname) if (pname !== '/favicon.ico') { fs.readFile('./html' + pname, function (err, data) { if(err){ res.end('404') }else{ res.writeHead(200, { 'content-type': 'text/' + name().split('.')[1] + ';charset=utf-8' }); res.write(data.toString()); res.end(); } }) } }).listen(3000, function () { console.log('start'); }) // let fs = require('fs'); // fs.mkdir('/upload',function(err,files){ // if(err){ // console.log('目录已经存在') // }else{ // console.log('创建成功'); // } // })