javascript - Node.js Which part i did wrong? server.js is running, but i cant see the html page -


this have far, running in putty,

var http = require('http'); var fs = require('fs'); const post =8080 http.createserver(function(request, response) {     var url = request.url;     switch(url) {     case '/':         console.log('1');         getstaticfilecontent(response,'templates/assignment1.html','text/html');         break;     case'/new':         console.log('2');         getstaticfilecontent(response,'templates/new.html','text/html');         break;     default:         response.writehead(404,{'content-type':'text/plain'});         response.end('404 - page not found.');      } }).listen(post)  console.log('server running');  function getstaticfilecontent(response, filepath, contenttype) {     fs.readfile(filepath, function(error, data) {         if (error) {             response.writehead(500,{'content-type': 'text/plain'});             response.end('500 - internal server error.');         }         if (data) {             response.writehead(200,{'content-type': 'text/html'});             response.end(data);         }     }); } 

when add console.log('1') in cases, these error pops out.

error: listen eaddrinuse @ errnoexception (net.js:901:11) @ server._listen2 (net.js:1039:14) @ listen (net.js:1061:10) @ server.listen (net.js:1135:5) @ object.<anonymous> (/net/files.cis.ksu.edu/exports/home/y/yuex/cis526/server.js:21:4) @ module._compile (module.js:456:26) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ function.module.runmain (module.js:497:10) 

can tell me did wrong?

the issue server listening same port, occupied application. free port, or try listen port. rest of code seems ok.

run linux command check if port listening occupied:

netstat -an | grep <port number> 

or

netstat -aon | more 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -