Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luzefiru/odin-basic-express-site
A simple Node.js backend application to route static HTML & CSS files to the client, built with Express.js.
https://github.com/luzefiru/odin-basic-express-site
Last synced: 19 days ago
JSON representation
A simple Node.js backend application to route static HTML & CSS files to the client, built with Express.js.
- Host: GitHub
- URL: https://github.com/luzefiru/odin-basic-express-site
- Owner: Luzefiru
- Created: 2023-04-21T01:39:36.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-23T16:43:00.000Z (almost 2 years ago)
- Last Synced: 2024-11-09T20:12:51.717Z (3 months ago)
- Language: HTML
- Homepage:
- Size: 75.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# odin-basic-express-site
A simple Node.js backend application to route static HTML & CSS files to the client, built with Express.js.
# Setup
```shell
git clone [email protected]:Luzefiru/odin-basic-node-site.git
cd ./odin-basic-node-site
npm run start
```# Serving Static CSS Files WITH Express.js
> You can see the code in the `node-version` branch.
An HTML file served by the server after a client initially gets it, can send another `'GET'` request to the server for any `href=` or `src=` files needed.
For example, here is `index.html` which is served when the client navigates to `host:port/`:
```html
Node Site
```
This HTML file then issues another `'GET'` request to resolve the `href="style.css"`. I can let Express.js serve these files via an `express.static(path)` directory. When the client (the `.html` file in this case) requests for `./style.css`, it will send a `GET host:port/style.css` HTTP request which Express.js can serve thanks to `express.static('public')`.
```js
/* /app.js */
app.use(express.static('public'));
```I can think of this as _"always listen to any `GET` requests for files inside the 'public' directory"_.
# Reference
These were the requirements in The Odin Project's [Project: Basic Informational Site](https://www.theodinproject.com/lessons/nodejs-basic-informational-site) page in order to practice pure Node.js server-side programming.