i'm new to nodeJS technology, Actually i want to create a server and provide routing to another two files based on request.url but i runs , it was showing the above error, where it is showing invalid status code,
Here is my code
app.js
var url = require('url')
var fs = require('fs')
function renderHTML(path , response){
fs.readFile(path,null, function(error , data){
if(error){
response.write('file not found')
} else{
response.writeHead(data)
}
response.end()
})
}
module.exports = {
handleRequest : function(request , response){
response.writeHead(200, {'Content-Type' : 'text/html'})
var path = url.parse(request.url).pathname;
switch(path) {
case '/' :
renderHTML('./index.html', response)
break;
case '.login' :
renderHTML('./login.html', response)
break;
default :
response.write('route not defined')
response.end()
}
}
}
And my server.js looks like
let http = require('http')
var app = require('./app.js')
http.createServer(app.handleRequest).listen(8001)
i have both index.html and login.html in my root directory..
what is the problem in above code. please help me.