Node rendered HTML file not finding relative path Scripts

前端 未结 1 1798
我在风中等你
我在风中等你 2021-01-13 03:09

New to node, and have it running pulling in an HTML page using Express and EJS

app.set(\'views\', __dirname + \'/views\');
app.engine(\'html\', require(\'ejs         


        
相关标签:
1条回答
  • 2021-01-13 03:45

    you should configure express to server static files, for example, put all the static files under a directory called 'public'

    app.configure(function () {
        app.use(express.cookieParser());
        app.use(express.bodyParser());
        app.use('/public', express.static(__dirname + '/public'));
        app.use(app.router);    
    });
    

    then in your html:

        <script src="/public/js/libs/jquery.js"></script>
    
    0 讨论(0)
提交回复
热议问题