DEV Community

mahirjain10
mahirjain10

Posted on

how to serve css and js file while serving html file via handlebars

I can give anydesk access to you if u want to help solving error

when I am serving CSS and JS file it showing the error

Refused to apply style from 'http://localhost:8000/public/css/index.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. Failed to load resource: the server responded with a status of 404 (Not Found) index.js:1

My index.hbs code

`


Employee Registartion









Insert Employee




Full Name



Email



Mobile



City



Submit


</div>
<script src="../public/js/index.js"></script>


My server.js code

` const express=require('express');
const app = new express();

const hbs=require('hbs');
const path=require('path');

app.use(express.json())// will convert string into obj
const employeeRouter=require('../controller/employee-controller');
require('../models/db')

app.use(employeeRouter);
app.use(express.static('public'));

const viewsPath=path.join(__dirname,"../views");
app.set('views',viewsPath);
app.set('view engine','hbs');

app.listen(8000,()=>{
console.log("connect to server bro");
})
`
Image description

Top comments (0)