首页 \ 问答 \ Node.js / Express没有输出console.log,highcharts.js给出了未定义的错误(Node.js/Express not outputting console.log, highcharts.js giving undefined error)

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
更新时间:2022-07-10 11:07

最满意答案

你可以这样使用:你应该将参数从参数传递给变量

$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

相关问答

更多
  • 没有一些“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 ...
  • 来自文档 : 可选细分 要使节可选,只需用方括号括起来 所以路由$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。 否则 ...
  • 您的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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)