Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.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
Node.js 节点JS继续获取无法加载资源错误消息_Node.js - Fatal编程技术网

Node.js 节点JS继续获取无法加载资源错误消息

Node.js 节点JS继续获取无法加载资源错误消息,node.js,Node.js,我目前正在测试node.js应用程序,并尝试添加: <link rel="stylesheet" href="assets/css/formalize.css" /> <script src="assets/js/jquery.formalize.js"></script> 知道我哪里出错了吗?这是我到目前为止的代码(在app.js中) 您需要将express.static中间件添加到app中,并使其指向包含静态资产的目录 例如,如果目录结构设置如下: a

我目前正在测试node.js应用程序,并尝试添加:

<link rel="stylesheet" href="assets/css/formalize.css" />
<script src="assets/js/jquery.formalize.js"></script> 
知道我哪里出错了吗?这是我到目前为止的代码(在app.js中)


您需要将
express.static
中间件添加到
app
中,并使其指向包含静态资产的目录

例如,如果目录结构设置如下:

app.js
index.htm
  static
    assets
      js
        jquery.formalize.js
      css
        formalize.css
app.use(express.static(__dirname + '/static'));
<link rel="stylesheet" href="/assets/css/formalize.css"/>
<script src="/assets/js/jquery.formalize.js"></script> 
您可以这样指定静态资产目录:

app.js
index.htm
  static
    assets
      js
        jquery.formalize.js
      css
        formalize.css
app.use(express.static(__dirname + '/static'));
<link rel="stylesheet" href="/assets/css/formalize.css"/>
<script src="/assets/js/jquery.formalize.js"></script> 
并在html文件中引用您的文件,如下所示:

app.js
index.htm
  static
    assets
      js
        jquery.formalize.js
      css
        formalize.css
app.use(express.static(__dirname + '/static'));
<link rel="stylesheet" href="/assets/css/formalize.css"/>
<script src="/assets/js/jquery.formalize.js"></script>