Skip to content

Instantly share code, notes, and snippets.

@Leodau
Created February 10, 2019 14:40
Show Gist options
  • Save Leodau/d6d83e18f3fdef77de041fbf650cf523 to your computer and use it in GitHub Desktop.
Save Leodau/d6d83e18f3fdef77de041fbf650cf523 to your computer and use it in GitHub Desktop.
Upload a sound file in NODEJS
const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.raw({ type: 'audio/wav', limit: '50mb' }));
app.get('/', (req, res) => res.send('Hello World!'));
app.post('/upload', function (req, res) {
console.log("RECIEVED: ", req.body);
fs.writeFile('audio.wav', req.body, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
res.send("Ok");
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment