Node.js - external JS and CSS files (just using node.js not express)

前端 未结 6 510
庸人自扰
庸人自扰 2020-12-02 12:52

Im trying to learn node.js and have hit a bit of a roadblock.

My issue is that i couldn\'t seem to load an external css and js file into a html file.



        
6条回答
  •  不知归路
    2020-12-02 13:12

    You might want to look into using server frameworks like express which allow you to set a 'public' directory for automatically routing static files

    var express = require('express'),app = express();
    app.use(express.static(path.join(__dirname, 'public')));
    

    The cheap overhead of such a framework would really be worth the effort of effectively 'reinventing the wheel'

提交回复
热议问题