I am trying to run this script on node and it requires apart from standard library the module : multiparty
var multiparty = require('multiparty');
var http = require('http');
var util = require('util');
http.createServer(function(req, res) {
if (req.url === '/upload' && req.method === 'POST') {
// parse a file upload
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
res.writeHead(200, { 'content-type': 'text/plain' });
res.write('received upload:\n\n');
res.end(util.inspect({ fields: fields, files: files }));
});
return;
}
// show a file upload form
res.writeHead(200, { 'content-type': 'text/html' });
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>'
);
}).listen(8080);
The script i am using is an official example given by the multiparty documentation. Since i am running this script in REPL mode of node, i decided to first install multiparty globally with this command
npm install -g multiparty
The module was installed and after that i tried to run it on node but i get the following error when uploading the file i.e. localhost:8080/upload
Uncaught TypeError : Cannot read property 'Form' of undefined
and also a Module Not found
error as seen below
I also tried installing multiparty with following command
npm install multiparty
But the error still persists.