📅  最后修改于: 2022-03-11 15:04:04.529000             🧑  作者: Mango
const http = require('http');const formidable = require('formidable'); const server = http.createServer((req, res) => { if (req.url === '/api/upload' && req.method.toLowerCase() === 'post') { // parse a file upload const form = formidable({ multiples: true }); form.parse(req, (err, fields, files) => { res.writeHead(200, { 'content-type': 'application/json' }); res.end(JSON.stringify({ fields, files }, null, 2)); }); return; } // show a file upload form res.writeHead(200, { 'content-type': 'text/html' }); res.end(` With Node.js "http"
module
`);}); server.listen(8080, () => { console.log('Server listening on http://localhost:8080/ ...');});