node 操作文件:
const fs = require('fs'); const path = require('path'); const filename = path.resolve(__dirname,'data.txt'); // 读取文件内容 fs.readFile(filename,(err,data)=>{ if(err){ console.log(err); } console.log(data.toString()); }) // 写入文件 const content = ' 的手机壳'; const opt = { flag:'a' // 'w'时重新覆盖,'a'是追加 } fs.writeFile(filename,content,opt,err=>{ console.log(err); }) //判断文件是否存在 fs.exists(filename,(exist)=>{ console.log('exist = '+exist); })
// 标准输入输出[控制台输入,同时输出] process.stdin.pipe(process.stdout) //【postman输入body,返回的就是body内容】 const http = require('http') const server = http.createServer((req, res) => { if (req.method === 'POST') { req.pipe(res) // 最主要 } }) server.listen(8000) // 复制文件,两个文件的拷贝 const fs = require('fs') const path = require('path') const fileName1 = path.resolve(__dirname, 'data.txt') const fileName2 = path.resolve(__dirname, 'data-bak.txt') const readStream = fs.createReadStream(fileName1) const writeStream = fs.createWriteStream(fileName2) readStream.pipe(writeStream) readStream.on('data', chunk => { console.log(chunk.toString()) }) readStream.on('end', () => { console.log('copy done') }) //get请求 获取文件的内容 const http = require('http') const fs = require('fs') const path = require('path') const fileName1 = path.resolve(__dirname, 'data.txt') const server = http.createServer((req, res) => { if (req.method === 'GET') { const readStream = fs.createReadStream(fileName1) readStream.pipe(res) } }) server.listen(8000)
一 sql 注入攻击
二 XSS攻击