Static files ဆိုတာ server က generate မလုပ်ဘဲ file အတိုင်းပြန်ပေးတဲ့ HTML, CSS, browser JavaScript, image, font စတာတွေပါ။ Express မှာ express.static() middleware နဲ့ static folder တစ်ခုကို public အဖြစ် serve လုပ်နိုင်ပါတယ်။
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.get('/api/message', (req, res) => {
res.json({ message: 'API and static files can work together.' });
});
app.listen(3000, () => {
console.log('Static server running at http://localhost:3000');
});app.use(express.static(...)) က public folder ထဲက files တွေကို browser ကတိုက်ရိုက်ရယူနိုင်အောင်လုပ်ပါတယ်။ ဥပမာ public/index.html ရှိရင် http://localhost:3000 မှာပြနိုင်ပါတယ်။
Static server running at http://localhost:3000 Browser shows public/index.html if it exists.Info
Static folder ထဲမှာ sensitive file, secret key, database backup မထည့်ပါနဲ့။ Public folder ဆိုတဲ့အတိုင်း browser ကရနိုင်တဲ့နေရာဖြစ်ပါတယ်။