Skip to content

Serving Static Files in Express #24

@moe-dizzle

Description

@moe-dizzle

In Express, one can use app.use and express.static to bind the absolute directory path such as user/home/nodeproject/public to a shortcut: /public, so that html can locate files using a relative path.
For an example expressApp.use('/public', require('express').static(process.cwd() + '/public')); With this I should be able to to display an image using a reative path in my html file, <img src="/public/img/goat.jpg" alt="chilling with a goat">. In the docs, can you show where app.use and express.static should be used ? I tried the init method on the config/web.js file, but it doesn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions