“Cannot Get /” When Trying to Connect to Localhost:8080 in Node. Js [Closed]
I Am Working on Backbone. Js Application with Node. Js as Backend Server. the Application Is Based on Twitter Api. When Requesting to Localhost:8080 I Got the...
I am working on backbone.js application with node.js as backend server.
the application is based on twitter API. When requesting to localhost:8080 I got the error "Cannot GET /" in the browser and I do not know what is the matter. My code is as follows:
server.js
var express = require('express');
var app = express();
var Twit = require('twit')
var client = null;
function connectToTwitter(){
client = new Twit({
consumer_key: 'xxx'
, consumer_secret: 'xxx'
, access_token: 'xxx'
, access_token_secret: 'xxx'
});
}
//get the app to connect to twitter.
connectToTwitter();
var allowCrossDomain = function(req, response, next) {
response.header('Access-Control-Allow-Origin', "");
response.header('Access-Control-Allow-Methods', 'OPTIONS, GET,PUT,POST,DELETE');
response.header('Access-Control-Allow-Headers', 'Content-Type');
if ('OPTIONS' == req.method) {
response.send(200);
}
else {
next();
}
};
app.configure(function() {
app.use(allowCrossDomain);
//Parses the JSON object given in the body request
app.use(express.bodyParser());
});
//Start server
var port = 8080;
app.listen( port, function() {
console.log( 'Express server listening on port %d in %s mode', port, app.settings.env );
});
Directory structure in general:
C:\Users\eva\Desktop\twitter application\server\server.js
\client\index.html
\js
Can someone tell me why this error occur?
You need to implement what server must response on / requests. For example:
app.get('/', function(req, res, next) {
res.send("Hello world");
});
Without it, express doesn't know how to handle /.