Node.js / Express没有输出console.log,highcharts.js给出了未定义的错误(Node.js/Express not outputting console.log, highcharts.js giving undefined error)
我来自PHP背景,但是第一次尝试使用Node / Express站点。 我已成功使用express-generator来获取在localhost上运行的基本框架。 我还通过npm安装了highcharts,并按照highcharts给出的说明通过require()将其添加到我的项目中。 我现在在我的index.js中有这个:
var express = require('express'); var Highcharts = require('highcharts'); var router = express.Router(); // Load module after Highcharts is loaded require('highcharts/modules/exporting')(Highcharts); console.log(Highcharts); // Create the chart Highcharts.chart('container', { /*Highcharts options*/ }); /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); module.exports = router;
我有两个问题:
1)运行DEBUG = project时,console.log()没有输出到终端或浏览器控制台:* npm start。 是输出到我没有检查的其他东西还是我需要做更多的事情才能看到这个?
2)要求('highcharts / modules / exports')(Highcharts); 抛出TypeError:在/Applications/MAMP/htdocs//node_modules/highcharts/modules/exporting.js:9:115无法读取未定义的属性'document'
我在哪里陷入困境?I'm from a PHP background but trying out a Node/Express site for the first time. I've successfully used express-generator to get the basic skeleton running on localhost. I've also installed highcharts via npm and followed the instructions given by highcharts to add it into my project via require(). I now have this in my index.js:
var express = require('express'); var Highcharts = require('highcharts'); var router = express.Router(); // Load module after Highcharts is loaded require('highcharts/modules/exporting')(Highcharts); console.log(Highcharts); // Create the chart Highcharts.chart('container', { /*Highcharts options*/ }); /* GET home page. */ router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); module.exports = router;
I have two questions:
1) console.log() is not outputting to terminal or browser console when running DEBUG=project:* npm start. Is it outputting to something else I haven't checked or do I need to do something more to see this?
2) require('highcharts/modules/exporting')(Highcharts); is throwing TypeError: Cannot read property 'document' of undefined at /Applications/MAMP/htdocs//node_modules/highcharts/modules/exporting.js:9:115
Where did I mess up?
原文:https://stackoverflow.com/questions/37083883
最满意答案
你可以这样使用:你应该将参数从参数传递给变量
$app->get('/bnb-details/{name}', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) { $name = $args['name']; include_once('bnb-details.php'); return $response; });
然后使用
echo $name;
在bnb-details.php中
you can use like this : you should pass parametere from args to variable
$app->get('/bnb-details/{name}', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) { $name = $args['name']; include_once('bnb-details.php'); return $response; });
then use
echo $name;
in bnb-details.php
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
没有一些“hacky”的东西,这将无法工作,因为我们无法访问slim的请求对象,而控制器构建完毕。 因此,我建议您只使用第3个参数并从那里获取用户ID。 “hacky”的东西是相同的,当你执行$app->run()时会有什么样的影响,但如果你真的想要这个,那么你会去: $c['Controller'] = function($c) { $routeInfo = $c['router']->dispatch($c['request']); $args = $routeInfo[2]; ...
-
你可以这样使用:你应该将参数从参数传递给变量 $app->get('/bnb-details/{name}', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) { $name = $args['name']; include_once('bnb-details.php'); return $response; }); 然后使用 echo $name; 在bnb-details ...
-
Slim 3路由参数(Slim 3 route parameter)[2021-10-17]
来自文档 : 可选细分 要使节可选,只需用方括号括起来 所以路由$app->get('/[{name}]'匹配任何URL字符串,包括none / 。 From the docs: Optional segments To make a section optional, simply wrap in square brackets So the route $app->get('/[{name}]' matches any URL string, including none /. -
Slim依靠加密的HTTP cookie来保存会话数据; 如果您没有cookie,除非您像上面所做的那样将会话处理程序设置为null ,否则将不会有会话。 版本1.6.0(目前在开发分支中)不对会话做任何假设; 相反,版本1.6.0要求您配置并启动自己的会话(如果使用PHP的本地会话处理)。 版本1.6.0还将传统会话处理抽象为中间件,以便您可以继续使用加密的Cookie来保存会话数据(如果您喜欢的话)。 如果您还有其他问题,我鼓励您将它们发布到http://help.slimframework.com/官 ...
-
你正在陷入悲痛,因为还没有配置Slim的错误处理,因为你的应用程序永远不会一直到\Slim\Slim::run() 。 两件事要做: 1)我建议将您的数据库类(和其他类似的类)添加到Slim的依赖注入容器中。 $app->container->singleton('db', function () use ($app) { return new Database($app); }); 这将允许延迟加载数据库连接。 在你使用它之前,这个类不会被创建。 在那一点上,我假设在这里,你将在一个路线中, \ ...
-
试试这个,我测试过了。 我运作良好。 get('/hello(/:name)', function ($name = 'default') { echo "Hello, $name"; }); $app->run(); 你可以这样访问: http://slim.test.com/hello http://slim.test.com/hello/srain 不能这 ...
-
您可以使用getArguments() - 方法执行此操作 public function __invoke($req, $res, $next) { $route = $req->getAttribute('route'); $args = $route->getArguments(); $lang = $args['lang']; return $res; } 注意:您还需要将slimRouteBeforeAppMiddleware的slim设置设置为true。 否则 ...
-
POST Slim Route无效(POST Slim Route not working)[2024-05-24]
您的Slim调用将返回页面上显示的任何内容。 有几种方法可以解决这个问题: 将所有页面渲染嵌套在路由中,并且不会为AJAX路由呈现完整页面。 修改您的AJAX调用以搜索返回的DOM以查找相关信息。 在您显示的示例中, AllHailSuccess! 将在site-index.php所有内容之后显示 许多人使用模板软件来呈现他们的页面,然后使用服务通过模板呈现他们的页面。 对于更基本的网站,我建议您创建一个简单的服务来显示内容。 以下是我在项目中使用的Viewer类的一个简单示例 class Viewer { ... -
路径占位符 : 对于“无限制”可选参数,您可以这样做: $app->get('/hello[/{params:.*}]', function ($request, $response, $args) { $params = explode('/', $request->getAttribute('params')); // $params is an array of all the optional segments }); Route placeholders: For “Unlim ...