I am new to using node/express and am just practicing to make sure I know how everything fits together. I was trying to get a simple html page with very simple css styling from the server using express, but I was running into some problems I haven't been able to solve.
This is the outline of my files for the projects: 1) "Name" is the file that hold all of these:
-node_modules
-public
-style.css
-app.js
-index.html
-package.json
Here is my code from my app.js file:
'use strict';
const express = require('express');
const app = express();
const path = require('path');
app.use('/',express.static(path.join(__dirname,'/public')));
app.get('/', (req, res, next) => {
res.sendFile(__dirname+'/index.html');
});
const server = app.listen(3000, () => console.log('listening on port 8080'));
If I type localhost:3000/style.css in the browser, the css file text shows up fine but when I type localhost:3000/ to get my index.html rendered with css, the network table in developer tools gives me a 404 saying it can't find my css document. I'm wondering if anyone knows why this is? Thanks!!!
via FlBloo
No comments:
Post a Comment