before i post my question you have to now that i'm new at using node.js.
So i'm buillding an image uploader using express, fs and easyimage and it's works fine. I want to show the final resized dynamic image in the client side (views) using jade.
This is my routes images.js file:
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res) {
res.send('home');
});
router.get('/upload', function(req, res) {
res.sendfile("./public/html/images-upload.html");
});
router.post('/upload', function(req, res) {
var multiparty = require("multiparty");
var form = new multiparty.Form();
form.parse(req, function(err,fields,files){
var img = files.images[0];
var fs = require("fs");
var easyimg = require("easyimage");
fs.readFile(img.path, function(err, data){
var path = "./public/images/"+img.originalFilename;
easyimg.rescrop({
src:"public/images/"+img.originalFilename, dst:"public/uploads/"+img.originalFilename,
width:150, height:150,
cropwidth:128, cropheight:128,
x:0, y:0
}).then(
function(image) {
console.log('Resized and cropped: ' + image.width + 'image.height);
},
function (err) {
console.log(err);
});
fs.writeFile(path, data, function(error) {
if(error) console.log(error);
//controller
var jade = require('jade');
res.render('home', {templateRender: jade.renderFile})
//template
});
});
});
});
module.exports = router;