- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 ubuntu 16.04 中使用 nodejs,并且我安装了 node 和 npm,但是当我尝试这个时出现了这个错误“TypeError: Cannot read property '_locals' of undefined”:
var express = require("express");
app = express();
bodyParser = require("body-parser");
mongoose = require("mongoose");
app.set("view engine", "ejs");
app.get("/", function(req,res){
app.render("index");
});
app.listen(3000, function(){
console.log("Server Started!");
})
它在终端输出:
Server Started!
TypeError: Cannot read property '_locals' of undefined
at EventEmitter.render (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/application.js:548:11)
at /home/luis/Documents/work/webdevBootcamp/test/app.js:9:6
at Layer.handle [as handle_request] (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/layer.js:95:5)
at next (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/layer.js:95:5)
at /home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/index.js:330:12)
at next (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/index.js:271:10)
at expressInit (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/middleware/init.js:33:5)
at Layer.handle [as handle_request] (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/index.js:312:13)
at /home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/index.js:280:7
at Function.process_params (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/index.js:330:12)
at next (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/router/index.js:271:10)
at query (/home/luis/Documents/work/webdevBootcamp/test/node_modules/express/lib/middleware/query.js:44:5)
当我加载 localhost:3000 时,它不会呈现 ejs 文件或让我使用它所执行的 send() 函数
app.get("/", function(req,res){
app.send("whatever");
});
它说:
TypeError: app.send is not a function
我确实安装了 express 和 ejs 模块(运行 npm install i -S express ejs mongoose body-parser)
最佳答案
正如@digit 在评论中所说:“您不应该调用 app.send 而不是 res.send。应用程序是用于路由 http 请求的对象。”
问题是我在做
app.get("/", function(req,res){
app.send("whatever");
});
代替
app.get("/", function(req,res){
res.send("whatever"); // res instead of app
});
关于javascript - 类型错误 : Cannot read property '_locals' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41458240/
我设置了我的安全设置来保护根路径下的所有内容 / , 除了用于查看隐私政策的公共(public)页面,/privacy .一切正常。 # security.yml access_control:
我试图通过添加上下文过滤器来更改日志记录格式。我的格式是这样的 FORMAT = "%(asctime)s %(VAL)s %(message)s" 这是我用来设置格式中的 VAL 的类。 class
我正在尝试实现一个 LocaleListener 来检测用户的首选语言(考虑 Accept-Language header )并将其存储在 session 中以避免每次请求都检查它。我开发了下面的代码
我在routing.yml中指定了每个路由中的参数_locale要求,我认为这一定可以简化这种情况。 路由.yml ProjectBaseBundle_index: pattern: /{_
我这里有一个测试内核,我从 Julia OpenCL API 调用它。我从 Julia 调用它这一事实并不重要,它只是我用来运行 OpenCL 的东西,这里是代码: using OpenCL cons
我目前正在为搜索 api 调整 elasticsearch。规范是: VM 上具有单个索引的 2 节点单集群(2 核 2GB RAM) 5 个碎片 1 次复制 使用 nginx 进行负载均衡 当我使用
全部!我想用安全系统一起保护我的应用程序。security.yml 文件下方 security: encoders: Symfony\Component\Security\Core\Use
我注意到我的本地变量中有从服务器收到的本地变量的副本。例如 Object { settings: "4.2", env: "development", utils: true,
我正在使用 Symfony 2 开发一个有 2 种语言的网站,我想根据用户区域设置语言更改路线模式! 示例: user_login_en: pattern: /en/user/login.h
这是我的 app/routing.yml FrontendBundle: resource: "@FrontendBundle/Resources/config/routing.yml" prefix
我正在尝试在 ubuntu 16.04 中使用 nodejs,并且我安装了 node 和 npm,但是当我尝试这个时出现了这个错误“TypeError: Cannot read property '_
我正在尝试让 gae-sessions 正常工作,但遇到了问题。 我已经登录到 appengine_config.py 内部和 webapp_add_wsgi_middleware 内部,它正在被调用
我在 python 中使用生菜时遇到了 AttributeError 问题。 我正在尝试遵循网站 http://lettuce.it/reference/terrain.html#reference-
我目前正在使用线程和所有这些编写基于 python 的数据报服务器。 我遇到了以下问题:我正在使用多个分配线程将传入的包分配给不同的处理线程。在处理线程中,我使用 threading.local()
我尝试添加全局参数 所有路由的参数,以及内核Request Listener中的参数设置。 路由 mea_crm: resource: @Crm4Bundle/Resources/config
我们将 Spring Data Elasticsearch 与地理分布的节点(和副本)一起使用。我们希望最小化跨边界的查询流量,并在“本地”节点上执行所有查询。无论如何要在全局范围内强制执行此操作吗?
在我的 Symfony2 项目中,我有一个包含帖子的新闻网站。这些帖子可以在不同地区发布。当前区域(用户选择)必须是 url 的一部分。因此 URL 应如下所示: /mag => main news
我正在 teamTreeHouse 上做这个教程 https://teamtreehouse.com/library/express-basics/using-templates-with-expre
我有一个 keras Sequential 模型,它在模型训练期间运行得非常好,但是当我尝试在训练模型上运行 model.predict 命令时, 我收到以下错误:- Traceback (most
我正在尝试为我的扩展更新 list 版本,但它给了我这个问题: default locale was specified, but _locales subtree is missing. 这是我的
我是一名优秀的程序员,十分优秀!