Node js/Express js relative paths (dot or __dirname or without any prefix)?

后端 未结 3 1352
借酒劲吻你
借酒劲吻你 2020-12-13 21:13

I\'m looking at Nodejs/expressjs and have seen different tutorials use either __diranme + \"/my_folder\", \"./my_folder\", or just \"my_folde

3条回答
  •  我在风中等你
    2020-12-13 21:41

    I use app.use(express.static(path.join(__dirname, 'public'))); which i then have three folders inside of my public, stylesheets, javascripts and images which allows me to access those static files by

       
       
    

    the ./myfolder approach I believe is essentially the same thing. I have never used it.
    the /myfolder approach I have never seen.

       require('./my_file.js') I use as 
       require('./routes/my_file.js') aand is where I store all my express routes.
    

    The require('myfile') is a call to packages that you install or come install with express.

提交回复
热议问题