Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js:未定义JustGage_Javascript_Html_Node.js_Npm_Justgage - Fatal编程技术网

Javascript Node.js:未定义JustGage

Javascript Node.js:未定义JustGage,javascript,html,node.js,npm,justgage,Javascript,Html,Node.js,Npm,Justgage,我正在尝试编写一个简单的基于node.js的应用程序,它可以使用JustGage(基于JavaScript的插件)。下面是我的Node.js应用程序 var http = require('http'); var fs = require('fs'); http.createServer(function (req, res) { fs.readFile('index.html', function(err, data) { res.writeHead(200, {'Content

我正在尝试编写一个简单的基于node.js的应用程序,它可以使用JustGage(基于JavaScript的插件)。下面是我的Node.js应用程序

var http = require('http');
var fs = require('fs');

http.createServer(function (req, res) {
  fs.readFile('index.html', function(err, data) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    res.end();
  });
}).listen(8080);
下面是index.html页面

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Temperature Sensor</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="static/resources/js/justgage.js"></script>
  <script type="text/javascript" src="static/resources/js/raphael-2.1.4.min.js"></script>

  <script>
    window.onload = function(){
      var g = new JustGage({
        id: "g_a411_faculty",
          value: 22, 
          min: 10,
          max: 40,
          title: "A411 - Faculty Office",
          label: "Celsius",
          levelColors: [
            "#ffffff",
            "#f9c802",
            "#FF0000"
          ]
      });
    };
  </script>
</head>
<body>
<div id="g_a411_faculty" class="col-sm-6" style="width:400px; height:320px"></div>
</body>
</html>
然而,当我写作的时候

var jg = require('justgage');

这显示引用错误-文档未定义。请帮忙

node.js没有为您的静态文件夹提供服务

当直接从文件夹运行时,网站可以工作,因为您可以从同一位置访问
static/..
的相对路径

当您通过node.js运行时,您只提供index.html,而不提供相关资产


在thread

中讨论了一些提供静态文件/文件夹的有用方法。node.js不提供静态文件夹

当直接从文件夹运行时,网站可以工作,因为您可以从同一位置访问
static/..
的相对路径

当您通过node.js运行时,您只提供index.html,而不提供相关资产


一些为静态文件/文件夹提供服务的有用方法将在现场发布的线程

中讨论!我创建了一个http服务器来承载剩余的文件,然后在src选项中使用了该链接!我创建了一个http服务器来承载其余的文件,然后在src选项中使用了该链接。
var jg = require('justgage');