node.js - Error: Cannot GET / -
i working in c9.io ide environment, have written below code in server.js file
var http = require('http'); var path = require('path'); var async = require('async'); var socketio = require('socket.io'); var express = require('express'); var express = require('express'); var app = express(); var router = express(); var server = http.createserver(router); server.listen(process.env.port || 3000, process.env.ip || "0.0.0.0", function(){ var addr = server.address(); console.log("server listening at", addr.address + ":" + addr.port); }); app.use(express.static(__dirname + '/client')); // respond "hello world" when request made homepage app.get('/', function(req, res) { res.render('index.html'); }); app.get('/about', function (req, res) { res.send('about'); });
after running node server.js in terminal message given
your code running @ https://nodejs2-mujaffar.c9.io. important: use process.env.port port , process.env.ip host in scripts! server listening @ 0.0.0.0:8080
but after accessing https://nodejs2-mujaffar.c9.io/ url -- not rendering view displaying message error: cannot /
what doing wrong?
please help.
you seem have created 2 instances of express may problem.
try changing:
var express = require('express'); var app = express(); var router = express(); var server = http.createserver(router);
to:
var express = require('express'); var app = express(); var server = http.createserver(app);
at minute, express app
variable not bound http server. have instead bounded unused instance called router
. have registered routes app
variable.
Comments
Post a Comment