I am trying to create an HTTP server with GET and POST, using Node.js, the user will upload images and archives. But the problem is that while trying to run the server, the command line from Node.js don't show to me the actual error, and point out to some line that doesn't exist.
Server.js
var url = require("url");
var http = require("http");
var formidable = require("formidable");
function start(route ,handle) {
function onRequest(request, response) {
var postData = "";
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " received.");
request.setEncoding("utf8");
request.addListener("data", function(postDataChunk) {
postData += postDataChunk;
console.log("Received POST data chunk ' " +
postDataChunk + " ' .");
});
request.addListener("data", function(chunk) {
//called when a new chunk of data was received
});
request.addListener("end", function() {
//called when all chunks of data been received
});
request.addListener("end", function() {
route(handle, pathname, response, postData);
});
}
var formidable = require('formidable'),
http = require('http'),
sys = require('sys');
http.createServer(function(req,res) {
if(req.url == '/upload' && req.method.toLowerCase() == 'POST') {
//parse a file upload
var form = new formidable.IncomingForm();
form.parse(req,function(err,fields,files) {
res.writeHead(200, {'content-type' : 'text/plain'});
res.write('received upload \n\n');
res.end(sys.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 typw="submit" value="upload"' +
'</form>');
}).listen(8888);
exports.start = start;
The only thing for sure is that I know that is happening in Server.js
because is pointed out to there.
server.js:69 - Unexpected token )
How can I get to know where this error is ? And maybe can be a lot of other sintax errors.
via Monteiro
No comments:
Post a Comment