Azure server can’t find handlebars views

I am using handlebars to generate html on my server and send it to my users when they land on my express routes. My route looks something like this :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
userRouter.get(
'/template-reset-password/:from',
async (req: Request, res: Response) => {
return res.status(200).render('reset-password', { data: req.data });
},
);
</code>
<code> userRouter.get( '/template-reset-password/:from', async (req: Request, res: Response) => { return res.status(200).render('reset-password', { data: req.data }); }, ); </code>

userRouter.get(
    '/template-reset-password/:from',
    async (req: Request, res: Response) => {
        return res.status(200).render('reset-password', { data: req.data });
    },
);

I’ve setup my express server to accept handleBars files as my view engine. Here’s the code I have in my index.ts file :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>app.engine(
'handlebars',
engine({
defaultLayout: false,
layoutsDir: `${__dirname}/public/html`,
}),
);
app.set('view engine', 'handlebars');
app.set('views', `${__dirname}/public/html`);
</code>
<code>app.engine( 'handlebars', engine({ defaultLayout: false, layoutsDir: `${__dirname}/public/html`, }), ); app.set('view engine', 'handlebars'); app.set('views', `${__dirname}/public/html`); </code>
app.engine(
    'handlebars',
    engine({
        defaultLayout: false,
        layoutsDir: `${__dirname}/public/html`,
    }),
);
app.set('view engine', 'handlebars');
app.set('views', `${__dirname}/public/html`);

On my local machine when i try to access this route, my server send me the html normally and my server can find the directory where my handlebar files are stored. But when I use the same code on my staging server, which is hosted on azure, the server can’t find the files and send me this error :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Error: Failed to lookup view "reset-password" in views directory "/usr/src/server/public/html"
at Function.render (/usr/src/server/node_modules/express/lib/application.js:597:17)
at ServerResponse.render (/usr/src/server/node_modules/express/lib/response.js:1039:7)
at /usr/src/server/adapters/primary/routes/user.route.js:114:28
at Generator.next (<anonymous>)
at /usr/src/server/adapters/primary/routes/user.route.js:8:71
at new Promise (<anonymous>)
at __awaiter (/usr/src/server/adapters/primary/routes/user.route.js:4:12)
at /usr/src/server/adapters/primary/routes/user.route.js:111:268
at Layer.handle [as handle_request] (/usr/src/server/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/src/server/node_modules/express/lib/router/route.js:144:13)
</code>
<code>Error: Failed to lookup view "reset-password" in views directory "/usr/src/server/public/html" at Function.render (/usr/src/server/node_modules/express/lib/application.js:597:17) at ServerResponse.render (/usr/src/server/node_modules/express/lib/response.js:1039:7) at /usr/src/server/adapters/primary/routes/user.route.js:114:28 at Generator.next (<anonymous>) at /usr/src/server/adapters/primary/routes/user.route.js:8:71 at new Promise (<anonymous>) at __awaiter (/usr/src/server/adapters/primary/routes/user.route.js:4:12) at /usr/src/server/adapters/primary/routes/user.route.js:111:268 at Layer.handle [as handle_request] (/usr/src/server/node_modules/express/lib/router/layer.js:95:5) at next (/usr/src/server/node_modules/express/lib/router/route.js:144:13) </code>
Error: Failed to lookup view "reset-password" in views directory "/usr/src/server/public/html"
    at Function.render (/usr/src/server/node_modules/express/lib/application.js:597:17)
    at ServerResponse.render (/usr/src/server/node_modules/express/lib/response.js:1039:7)
    at /usr/src/server/adapters/primary/routes/user.route.js:114:28
    at Generator.next (<anonymous>)
    at /usr/src/server/adapters/primary/routes/user.route.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/usr/src/server/adapters/primary/routes/user.route.js:4:12)
    at /usr/src/server/adapters/primary/routes/user.route.js:111:268
    at Layer.handle [as handle_request] (/usr/src/server/node_modules/express/lib/router/layer.js:95:5)
    at next (/usr/src/server/node_modules/express/lib/router/route.js:144:13)

I figured this probably has to do with my azure server config not accepting .handlebar files type, and sending me a “not found” error. Since I’m really new at azure I’d appreciate deep explanations on how to resolve this error. Thanks in advance.

I tried to use handlebars engine on my azure server just like on my local machine. I’ve encountered the same issue trying to use EJS templates.

New contributor

user25033210 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật