History: Photo sharing service

Revision made 3 years ago by Francisco Presencia. Go to the last revision.

We are going to create a photo sharing service where the user is able to upload pictures and like them.

We will be using a simple MVC, so our file structure will be:

  /users.js # this will be half-mocked up since there's no time
            # or we'll use auth0 if possible

The user will be able to login (actually no, we will fake this)

For this, first we set up our app.js:

// Parse the .env config automatically

var express = require('express');
var bodyparser = require('body-parser');

var app = express();

app.set('view engine', 'pug');

app.listen(process.env.PORT || 3000);

Then in our controllers/photos.js:

var formidable = require('formidable');
var cloudinary = require('cloudinary');

  cloud_name: process.env.cloud,
  api_key: process.env.key,
  api_secret: process.env.secret

exports.upload = function(req, res, next){
  var form = new formidable.IncomingForm();
  form.parse(req, function (err, fields, files) {
    if (err) next(err);
    cloudinary.uploader.upload(files.image.path, function(result) {
      // Let's force https in the image:
      var image = result.url.replace('http://', 'https://');
      res.json({ error: false, image: image });

Our layout.pug:

doctype html
    title= title
    link(rel="stylesheet" href="https://cdn.jsdelivr.net/picnicss/6.0.0/plugins.min.css")
    link(rel='stylesheet', href='style.css')
    block content

In photos.pug:

extends layout

block content
  each photo in photos


We will follow Auth0 tutorial.