If you want to use the standard HTML templates in your Node JS app without Jade, you use path to get the location of where you are located.
Then use __dirname to get your root directory name, the one where your project resides. Then we simply append our folder locations.
Also be sure to use express.static to append folder so that you can access them. They are public.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
var express = require("express"); var app = express(); var path = require("path"); app.use(express.static(__dirname + '/View')); //Store all HTML files in view folder. app.use(express.static(__dirname + '/Script')); //Store all JS and CSS in Scripts folder. app.get('/index',function(req,res){ console.log('path is: ' + path); console.log(path.join(__dirname + '/View/index.html')); res.sendFile(path.join(__dirname + '/View/index.html')); }); app.get('/contact',function(req,res){ console.log('path is: ' + path); console.log(path.join(__dirname + '/View/contact.html')); res.sendFile(path.join(__dirname + '/View/contact.html')); }); app.listen(3000); console.log("Running at Port 3000"); |