在不使用multer的情况下,可以使用Node.js中的内置模块fs来处理文件上传。
下面是一个示例代码,演示如何使用fs模块将文件从客户端上传到服务器:
http模块创建一个简单的服务器:const http = require('http');
const fs = require('fs');
const server = http.createServer((req, res) => {
  if (req.url === '/upload' && req.method === 'POST') {
    let body = '';
    
    req.on('data', (chunk) => {
      // 接收请求正文的数据
      body += chunk;
    });
    req.on('end', () => {
      // 解析请求正文
      const fileData = Buffer.from(body, 'binary');
      // 将文件保存到服务器
      fs.writeFile('uploaded_file.txt', fileData, (err) => {
        if (err) {
          console.error(err);
          res.statusCode = 500;
          res.end('File upload failed');
        } else {
          res.statusCode = 200;
          res.end('File uploaded successfully');
        }
      });
    });
  } else {
    res.statusCode = 404;
    res.end('Not found');
  }
});
server.listen(3000, () => {
  console.log('Server is running on port 3000');
});
在上述代码中,当收到/upload的POST请求时,首先我们监听data事件来接收请求正文的数据,然后监听end事件来处理完整的请求。接着,我们使用fs.writeFile()方法将文件数据写入服务器上的一个名为uploaded_file.txt的文件中。
请注意,上述示例代码只是一个简单的示例,并未包含文件类型验证、文件大小限制等安全性和性能方面的考虑。在实际生产环境中,建议使用成熟的文件上传解决方案,如multer,以确保安全性和可靠性。