【问题标题】:Why Node js doesn't see files in node_modules folder [duplicate]为什么Node js看不到node_modules文件夹中的文件[重复]
【发布时间】:2018-05-24 21:26:47
【问题描述】:

我添加到我的 html 页面:

<script src="/node_modules/angular/angular.min.js"></script>

但我有错误:

获取http://localhost:30003/node_modules/angular/angular.min.js404 (未找到)

我试图添加到我的服务器文件中:

app.use(express.static(__dirname + '/node_modules/'));

它没有帮助。 请告诉我如何解决?

【问题讨论】:

    标签: node.js express


    【解决方案1】:

    这样使用:

    app.use('/scripts', express.static(__dirname + '/node_modules/angular/'));
    

    然后在你的 HTML 中你可以像这样得到它:

    <script src="/scripts/angular.min.js"></script>
    

    【讨论】:

    • 它工作正常,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    • 2016-03-25
    • 2020-11-27
    相关资源
    最近更新 更多