is there a way to add CSS/JS later using EJS with nodejs/express

后端 未结 5 1482
情歌与酒
情歌与酒 2021-02-01 09:26

i\'m using the EJS template engine with nodejs/express and i\'m wondering if it\'s possible to add another css or js file in e.g the index.ejs (not the layout.ejs)

5条回答
  •  没有蜡笔的小新
    2021-02-01 10:06


    In app.js add line:

    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use(express.static(__dirname + '/public')); // This line.
    

    In layout.ejs:

    
    
      
        Authentication Example
        
            
      
      
        <%- body %>
      
    
    

    In index.ejs or login.ejs:

    Login


    In test.js:

    $(document).ready(function() {
        try{
            alert("Hi!!!");
        }catch(e)
        {
            alert("Error");
        }
    });
    

    Regards.

提交回复
热议问题