Can't load local files when using NodeJS server

前端 未结 2 742
盖世英雄少女心
盖世英雄少女心 2020-12-22 10:41

I\'m very new to NodeJS, and I\'m currently playing around with it (and websockets), so this question might be a bit dumb. Anyway, I\'m following a tutorial which has given

2条回答
  •  时光取名叫无心
    2020-12-22 11:23

    you can specify to the server in which folder to look for what

    for static files such as css, images you can use public directory, you can provide your custom directory, but it's better to use public ,same goes for views

    always require

    const PATH = require('path')

    app.use(express.static(PATH.join(__dirname, 'public')));
    

    for template files such as .ejs, .html, .jade use

    app.set('views', PATH.join(__dirname, 'views'));
    

提交回复
热议问题