score:1
Accepted answer
assuming your server.js file and your public directory exist at the same level, the path.resolve(__dirname, 'public')
will build the full path to the public directory where all of your static resources should exist. when you reference these files inside your html pages you specify the path relative to the public directory.
<link href="css/main.css"/>
this should be enough to find the file. assuming that file exists at ../public/css/main.css
.
Source: stackoverflow.com
Related Query
- Serve static files using html string in express.js
- node express Server does not serve compressed static files with brotli and gzip compression
- Serve static html files in PWA if service worker is configured in CRA
- Can't Serve Static HTML File with Express / Node
- How to query by text string which contains html tags using React Testing Library?
- Is it possible to serve Static files with create-react-app from public folder?
- Webpack: How to compile, write on disk and serve static content (js/css) using webpack-dev-server
- Using Static HTML with React
- How to serve ReactJS static files with expressJS?
- React app is looking for static files in different location when using proxy
- Authentication to serve static files on Next.js?
- Express Static files on server not loading correctly but React Front end is loading correctly?
- Sanitize HTML String without using dangerouslySetInnerHTML for length check
- Serving react static files in golang gin-gonic using go:embed giving 404 error on reloading on frontend URL
- Serving REACT component using express is not working (just html file is rendered)
- Getting line breaks with string literals in html elements using React
- Express not serving static files correctly for react build
- How to render a html string content in PDF using JsPDF in ReactJS
- Gatsby not generating correct static HTML files
- How to serve the same static files regardless of the route?
- Send data to a route using Express JS when you are serving a static file for React-Router
- Losing query string by refreshing page in Nextjs using express
- using React JS components in django teamplates though static files (hybrid model) - what's wrong? (newbie JS/React question)
- Express server serves my static files but does not handle requests to my API. What is happening?
- React Js front end and Express backend - can't load static files properly
- Using react-quill for a blog app so users can create posts. How do I properly display a string of html elements in React?
- replace string text with html tag using regex
- Server cannot serve static files
- Fetching data from API and using it in JSX is giving string output to the html tag
- Serve React build files from two different static build directories
More Query from same tag
- how to change the asterisk color in required * field
- Edit button tooltip color Prime React
- How to scroll a fixed area only, not the whole page onClick?
- Input not being read properly in React function (no JSX)
- React Modal Closing Early
- Unable to use two modals on same page using useDisclosure() in ChakraUI
- Is it wrong to use shorthand if/else statements in this way
- Pass data (prop) from _app.js to getServerSideProps in a page - NextJS, latest version
- CORS error - Error: Cross origin http://localhost forbidden - in ReactJS/Jest test only
- Reactjs - How to prevent assigning of null during editting a form
- Increase Like count if post id is equal to action.payload
- useEffect hook is running an infinite loop even when a second argument is provided
- React - Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render
- React - input checkbox onchange won't fire first time
- array reducer is concatenating. not adding to sum. context with react
- How to debug line by line in REACT using VS code editor?
- SVG path point at lat and long rather than side of SVG
- Conditional if else list data in react
- Handling paginated links using a MobX store and React components?
- React, pass component as a child and then render it with new prop
- functional react: how to handle setState with an input from map function?
- useState not setting after initial setting
- New React Native project with old version of react native
- How to pass an array object from a component to a page in reactjs
- Material UI component breaking React application
- eslint: no-case-declaration - unexpected lexical declaration in case block
- React.js async rendering: when componentWillMount will be called multiple times
- Restricting type of children
- Access Table Header Row Key React
- Max-height and max-width for divs with dynamic backgrounds?