unknown
unknown

Reputation: 397

Serve static images/files from NodeJS URL localhost to VueJS

What is the correct code format to establish the static server from nodejs

This is my current code to declare the static server and won't work

app.use(express.static( './src/uploads'));

My URL that used to be fetch by Vuejs from nodejs folder

http://localhost:5000/src/uploads/100-cities-with-the-most-beautiful-women-in-the-world.jpg

As you can see on the image this is the folder structure

-ecommerce-backend

 -src

  -uploads

As you can

Upvotes: 0

Views: 232

Answers (1)

Krishnadas PC
Krishnadas PC

Reputation: 6519

A working code used in one of my projects is

var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));

You can replace public with your dir name. The directory structure for the project is

-routes
-models
-public
app.js

Nodejs version is

node -v
v10.16.0

Upvotes: 1

Related Questions