DEV Community


Posted on

Not defined error while passing data from node js to EJS

My app.js:

const multer = require("multer");
const path = require("path");

const storage = multer.diskStorage({
destination: './upload/images',
filename: (req, file, cb) => {
return cb(null, ${file.fieldname}_${}${path.extname(file.originalname)})

const upload = multer({
storage: storage,
fileSize: 10485760
app.use('/profile', express.static('upload/images'));"/upload", upload.single('profile'), (req, res) => {
success: 1,
profile_url: http://localhost:3000/profile/${req.file.filename}
var imgPath = req.file.path;

function errHandler(err, req, res, next) {
if (err instanceof multer.MulterError) {
success: 0,
message: err.message

My Ejs file:

<%= imgPath%>

Hope you all guys are doing good. I am new to node js, express js, ejs, I am stuck in this problem for 2 days now and I am not able to figure out where I am wrong. :(

Top comments (1)

rafarochas91 profile image
Rafael Rocha

The variable that you're passing into your ejs file in the render method is profile_url. You need to pass the variable you wish to the render method.