// Multer is middleware for node that can handle multipart/form-data
    // and file uploads.
  
const express = require('express');
const app     = express();

const multer = require('multer');
const upload = multer();

app.post('/upload', upload.single('file'), (req, res) => {
  /*
    req.file is an object with the following properties:
    fieldname, originalname, encoding, mimetype, size, and buffer.
    req.file.buffer contains the contents of the file in a
    buffer object.
  */
  res.send('File uploaded.');
});

app.use('/', (req,res) => res.send(`
  <form action="/upload" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <button type="submit">Submit</button>
  </form>
`));

let port = 8000;
app.listen(port);
console.log(`HTTP server listening on port #${port}.`);


// https://sean.brunnock.com  1/2025