/devport

MERN Application for developers to connect. Create, view profiles and build connections. User can showcase details like education, experience, skills, github repository details, biography in the profile.

Primary LanguageJavaScript

A MERN Application for developers to connect.

Modules Used

Chat to be added in next release

Express

const express = require('express')
const app = express()

app.get('/', function (req, res) { res.send('Hello World') }); app.listen(3000);

Mongoose

  mongoose.connect('mongodb://localhost/my_database', {
  useNewUrlParser: true,
  useUnifiedTopology: true
Schema Definition
  const Schema = mongoose.Schema;
  const ObjectId = Schema.ObjectId;

const BlogPost = new Schema({ author: ObjectId, title: String, body: String, date: Date }); });

Bcrypt

  var bcrypt = require('bcryptjs');
  bcrypt.genSalt(10, function(err, salt) {
      bcrypt.hash("B4c0/\/", salt, function(err, hash) {
          // Store hash in your password DB.
      });
  });

// Load hash from your password DB. bcrypt.compare("B4c0//", hash, function(err, res) { // res === true });

Json Web Token

 jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' }, function(err, token) {
    console.log(token);
  });
  // verify a token symmetric
jwt.verify(token, 'shhhhh', function(err, decoded) {
    console.log(decoded.foo) // bar
  });
  

Gravatar

  gravatar.url(email);
  gravatar.url(email, options);
  gravatar.url(email, options, protocol);
  

Express Validator

  app.post('/user', [
    // username must be an email
    check('username').isEmail(),
    // password must be at least 5 chars long
    check('password').isLength({ min: 5 })
  ], (req, res) => {
    // Finds the validation errors in this request and wraps them in an object with handy functions
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.status(422).json({ errors: errors.array() });
    } 
    

Concurrently

  npm install concurrently --save
  In package.json, escape quotes:
  "start": "concurrently \"command1 arg\" \"command2 arg\""
  

Nodemon

  To run the backend server automatically when any changes are done.
  

Client - React

  npx create-react-app my-app
  cd my-app
  npm start
  

Deployment - building static assets

direct push
  npm run build
  

heroku

  //package.json
  scripts: {
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  }
  //server mods
  if(process.env.NODE_ENV === 'production'){
      //set static path
      app.use(express.static('client/build'));
      app.get('*', (req, res) => {
          res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
      });
  }