Ich habe Bilder in "/ public/images" Pfad eingefügt. Jetzt in der Antwort bekomme ich URL wie ich wollte. Aber sobald ich diese URL in den Webbrowser einfüge, heißt es Kann nicht /public/images/food-1-xxhdpi.png. Also sollte ich separate API schreiben, um damit umzugehen?kann Bild aus Ordner in node.js nicht lesen
Hauptdatei app.js
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var app = express();
var PORT = 3000;
var foodtrucklist = require('./controller/foodtrucklist.js');
var foodtruck = require('./model/datafoodtruck');
var db = mongoose.connect('mongodb://127.0.0.1:27017/quflip');
mongoose.connection.once('connected', function() {
console.log("Connected to database")
foodtruck.save(function(err,foodtrucks){
if (err) res.send(err);
});
});
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/public/images'));
app.get('/foodtrucklist',foodtrucklist);
app.listen(PORT,function() {
console.log('express listining on port' + PORT);
});
App. use ('/ public/images', express.static (__ Verzeichnisname + '/ public/images')); arbeitete für mich. Danke –