javascript - Using TypeScript and Express, views do not render. Instead server files are shown -


i'm trying create webapp using typescript. have app.js file creating server, route i'm defining never hit. instead, files on server @ root of project shown.

here code.

//app.ts import * express 'express'; import * http 'http-server';  let app = express();  app.set('port', 443); app.set('views', './views'); app.set('view engine', 'jade');  app.get('/', function(req: any, res: any) {     // code never reached on 'get /' requests.     res.render('index'); });  app.use(function(req: any, res: any, next: any) {}); app.use(function(err, req, res, next) {});  http.createserver().listen(app.get('port'));  console.log("listening..."); 

when go localhost:443 i'm met image below.

showing server files instead of rendering

in messing around code i'm able app.render() call see rendered html string in debugger, more can out of configuration, still calling app.render('index'); doesn't render anything. sample below.

app.render('index', function(err: error, html: string) {     console.log(html); // outputs rendered view, not rendered on page. }); 

what think?

you haven't used express instance server.

you need this

http.createserver(app).listen(app.get('port')); 

or

app.listen(app.get('port')) 

basically called server without handler, shows directory of main script.

you have created express instance, did not added http server.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -