This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mocha_tdd", | |
"version": "0.0.1", | |
"private": true, | |
"scripts": { | |
"start": "nodemon ./bin/www --exec babel-node --presets es2015", | |
"test": "sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all && ./node_modules/.bin/mocha --require babel-register --recursive", | |
}, | |
"dependencies": { | |
"babel-core": "^5.8.38", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"extends": "airbnb", | |
"plugins": [ | |
"import" | |
], | |
"root": true, | |
"env": { | |
"node": true, | |
"es6": true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"presets": ["es2015"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"development": { | |
"username": "postgres", | |
"password": "", | |
"database": "testdev", | |
"host": "127.0.0.1", | |
"dialect": "postgres" | |
}, | |
"test": { | |
"username": "postgres", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const logger = require('morgan'); | |
const bodyParser = require('body-parser'); | |
const cookieParser = require('cookie-parser'); | |
const session = require('express-session'); | |
const jwt = require('jsonwebtoken'); | |
process.env.SECRET_KEY = 'example'; | |
const app = express(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import usersController from '../controllers/users'; | |
// const auth = require('../../middleware/auth'); | |
const path = require('path'); | |
module.exports = (app) => { | |
// Creates a new user. | |
app.post('/api/users', usersController.create); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jwt = require('jsonwebtoken'); | |
module.exports = { | |
authenticate: (req, res, next) => { | |
const token = req.body.token || req.query.token || req.headers['x-access-token']; | |
if (token) { | |
jwt.verify(token, process.env.SECRET_KEY, (error, decoded) => { | |
if (error) { | |
return res.json({ | |
message: 'Failed to authenticate token.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mongoose = require('mongoose'); | |
let User = require('../models/user'); | |
function createUser(req, res) { | |
var newUser = new User(req.body); | |
newUser.save((err,user) => { | |
if(err) { | |
res.send(err); | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let express = require('express'); | |
let app = express(); | |
let mongoose = require('mongoose'); | |
let morgan = require('morgan'); | |
let bodyParser = require('body-parser'); | |
let port = 5000; | |
let user = require('./controllers/user'); | |
mongoose.connect("127.0.0.1:27017"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mongoose = require('mongoose'); | |
let Schema = mongoose.Schema; | |
let UserSchema = new Schema( | |
{ | |
firstName: { type: String, required: true }, | |
lastName: { type: String, required: true }, | |
emailAddress: { type: String, required: true }, | |
username: { type: String, required: true}, | |
password: { type: String, required: true }, |
OlderNewer