Tengo la siguiente aplicacion de nodejs
usando expressjs
:
app.js
const express = require("express");
const app = express();
const main = require("./main/main");
const port = 3000;
const path = require("path");
app.set("view engine", "ejs");
app.use(express.static(path.join(__dirname+"/static/css")));
app.use(express.static(path.join(__dirname+"/static/js")));
app.use("/", main);
app.use("/contacts", contacts);
app.listen(port, () => console.log("Online"));
main.js
const express = require("express");
const router = express.Router();
const path = require("path");
router.get("/", (req, res) => res.sendFile(path.join(__dirname+"/main.html")));
module.exports = router;
main.html
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="static/css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<h1>Hi</h1>
<div class="card-panel teal lighten-2">This is a card panel with a teal lighten-2 class</div>
<!--JavaScript at end of body for optimized loading-->
<script type="text/javascript" src="/static/js/materialize.min.js"></script>
</body>
</html>
Cuando ejecuto la aplicacion el documento me arroja el siguiente error:
Refused to apply style from 'http://localhost:3000/static/css/materialize.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
GET http://localhost:3000/static/js/materialize.min.js 404 (Not Found)
Refused to execute script from 'http://localhost:3000/static/js/materialize.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
¿Como puedo aplicar el estilo materialize-css en express js?