While working on an express project, I am trying to use the express.Router object to process the routes of my application. In my main application file, I added a static route for all my static files (css, javascript, html).
app.js
var express = require('express'); var io = require('socket.io')(app); var bodyParser = require('body-parser'); var router = require('./include/router'); var app = express(); app.use('/', router); app.use(express.static(__dirname + '/public')); app.use(bodyParser.json()); io.on('connection', function(socket) { }); app.listen(3000);
router.js
var express = require('express'); var path = require('path'); var router = express.Router(); router.get('/', function(req, res) { res.sendFile('/html/index.html'); }); module.exports = router;
When I try to access localhost:3000 , I get a 404 message showing Error: ENOENT, stat 'C:\html\index.html'
Also, when I try to access the static route directly ( http://localhost:300/html/index.html I believe), but it gives me Cannot GET /html/index.html .
This is my public folder tree
public
ββββcss
ββββhmtl
| ββββindex.html
ββββimg
ββββjs
Am I laying it wrong? How can i fix this?
James_Parsons
source share