I am beginning to code in Javascript and Nodejs. I am checking if a post call has been made to recFile and accept the file sent. For all other http requests made I want to return a static HTML page. When I tried res.redirect it said 'res.redirect is not a function'
const bodyparser = require('body-parser');
var http = require('http');
var formidable = require('formidable');
var fs = require('fs');
const express =require('express');
const { response } = require('express');
const app = express();
http.createServer(function (req, res) {
if (req.url == '/recFile') {
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var oldpath = files.filetoupload.path;
var newpath = './Uploads/' + files.filetoupload.name;
fs.rename(oldpath, newpath, function (err) {
if (err) throw err;
res.write('File uploaded and moved!');
res.end();
})
});
} else {
// Need to send user here to a HTML page. But don't know how to do that.
// res.write is not viable as there is a lot of HTML lines of code.
return res.end();
}
}).listen(9000);