Express with gravatar

2.1k views Asked by At

I make web site with express and I need gravatar image, so https://npmjs.org/package/gravatar

npm install gravatar

and my app.js

in my app.js

var gravatar = require('gravatar');
http.createServer(app).listen(app.get('port'), function(){
  var secureUrl = gravatar.url('[email protected]' ,  {s: '100', r: 'x', d: 'retro'}, true);
  console.log(secureUrl);
  console.log('Express server listening on port ' + app.get('port'));
});

working very well, and Browser show me nice picture.

but I use express, and use post method like this,

app.post('/signup', routes.signupResult);

and full of my example source index.js

exports.signupResult = function(req, res){
  res.render('user/signup-result', {
  title: 'Node-Chat Sign up'
  , name: req.body.name
  , email: req.body.email
  , password: req.body.password
  , password: req.body.passwordConfirmation
});

};

I want my signup-result.jade will use gravatar profile image... what can I do my app.js to routes/index.js edit for gravatar?

2

There are 2 answers

1
Mathieu Amiot On BEST ANSWER

You forgot to require the gravatar lib in your index.js file.

Add this at the top :

var gravatar = require('gravatar');

And also, in your render call add this

avatar: gravatar.url(req.body.email , {s: '100', r: 'x', d: 'retro'}, true).

1
AudioBubble On

i always use this code for getting a gravatar:

  <?php
$userMail = "[email protected]";

$imageWidth = '150';

$imgUrl = 'http://www.gravatar.com/avatar/'.md5($userMail).'fs='.$imageWidth;

echo "<img src=\"" . $imgUrl . "\">";
?>

by the way i don't know if that email really exists