Skip to content

Instantly share code, notes, and snippets.

View AshutoshSajan's full-sized avatar
🤓
Making web apps

Ashutosh Sajan AshutoshSajan

🤓
Making web apps
View GitHub Profile
@AshutoshSajan
AshutoshSajan / operators.js
Created January 15, 2019 07:36
comma operator
var a = 1, b = 3 ,c = 4 , d = 5;
var a = 1,
b = 3,
c = 5;
var a = 1
,b = 3
,c = 5;
const jwt = require("jsonwebtoken");
const User = require("../models/User");
function createToken (id, secret) {
return jwt.sign({
userId: id
},
secret, {
expiresIn: "72h"
})
const User = require("../models/User");
const bcrypt = require('bcrypt');
const jwtAuth = require('../utils/jwtAuth');
function loginUser (req, res){
User.findOne({
email: req.body.email
})
.exec((err, user) => {
if (err) {
function handleLogin (){
let user = {
userName: 'Jhon Doe',
email: '[email protected]',
password: 'superstar@123'
}
const BASE_URL = 'http://localhost:3000/api/v1'
fetch(BASE_URL + '/users/login', {
require('dotenv').config();
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const mongoose = require('mongoose');
const cors = require("cors");
const indexRouter = require('./routes/index');
const User = require("../models/User");
const bcrypt = require('bcrypt');
const jwtAuth = require('../utils/jwtAuth');
module.exports = {
// create/register user
registerUser: (req, res) => {
User.findOne({
email: req.body.email
function verifyToken (req, res, next) {
var token = req.headers.Authorization || req.headers.authorization || "";
if (!token) {
res.status(401).json({
success: false,
message: "please authenticate."
});
} else if (token) {
jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
function getQuestion(req, res) {
const id = req.params.id;
Question.findOne({
_id: id
}, (err, question) => {
if (err) {
res.status(500).json({
success: false,
error: err,
function isAdmin (req, res, next) {
const id = req.user.userId;
User.findOne({
_id: id
}, (err, user) => {
if (err) {
res.status(500).json({
success: false,
message: "server error",
function deleteQuestion (req, res) {
const id = req.params.id;
Question.findOneAndDelete({
_id: id
}, (err, question) => {
if (err) {
res.status(500).json({
success: false,
error: err,