为什么“无法获得/”被展示为简单的哈巴狗渲染?

时间:2016-10-02 04:30:51

标签: javascript node.js express pug

尝试使用基本的哈巴狗模板设置基本的Express服务器。

你可以告诉我这里我做错了什么吗?

addFlags()

我在控制台中找回'use strict'; //Require Express var express = require('express'); var app = express(); //Require Pug var pug = require('pug'); //Require Twitter var Twitter = require('twitter'); //Set view engine to serve middleware app.set('view engine', 'pug'); //Set where to look for templates app.set('views', __dirname + '/templates'); //Set up style sheets app.use('/static', express.static(__dirname + '/public')); //Access keys to access twitter account var config = { "consumerKey": "", "consumerSecret": "", "accessToken": "", "accessTokenSecret": "" }; //instantiate twitter client var client = new Twitter(config); //Log whether var error = function (err, response, body) { console.log('ERROR [%s]', err); }; var success = function (data) { console.log('Data [%s]', data); }; //Set up server on Port 3000 app.listen(3000, function() { console.log("The frontend server is running on port 3000!"); }); //Render when appropriate //Tell app to render template app.get('/'), function(req, res){ res.render('index', {title: 'Hey', message: 'Hello there!'}); }

我错过了什么?

我非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

您正在调用app.get()错误。你在做什么

app.get('/'), function(req, res){
   ...

这是由逗号运算符分隔的两个语句。正确的语法是将函数作为第二个参数传递:

app.get('/', function(req, res){
   ...
});