最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Express with gravatar - Stack Overflow

programmeradmin1浏览0评论

I make web site with express and I need gravatar image, so

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?

I make web site with express and I need gravatar image, so https://npmjs/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?

Share Improve this question asked Dec 17, 2013 at 9:02 ChangJoo ParkChangJoo Park 9791 gold badge11 silver badges29 bronze badges 1
  • oh my .. using var gravatar = require('gravatar'); inside index.js. it's done – ChangJoo Park Commented Dec 17, 2013 at 9:16
Add a ment  | 

2 Answers 2

Reset to default 9

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).

i always use this code for getting a gravatar:

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

$imageWidth = '150';

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

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

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

发布评论

评论列表(0)

  1. 暂无评论