Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const bodyParser = require('body-parser');
- const cors = require('cors');
- const morgan = require('morgan');
- const {sequelize} = require('./models');
- const config = require('./config/config');
- const app = express();
- app.use(morgan('combined'));
- app.use(bodyParser.json());
- app.use(cors());
- require('./routes')(app)
- sequelize.sync()
- .then(() => {
- app.listen(config.port);
- console.log(`Server startet on port:${config.port}`);
- })
- module.exports = {
- port : process.env.PORT || 9000,
- db : {
- database : process.env.DB_NAME || 'tabtracker',
- user : process.env.DB_USER || 'tabtracker',
- password : process.env.DB_PASS || 'tabtracker',
- options : {
- dialect : process.env.DIALECT || 'sqlite',
- host : process.env.HOST || 'localhost',
- storage : './tabtracker.sqlite'
- }
- }
- }
- const fs = require('fs');
- const path = require('path');
- const Sequelize = require('sequelize');
- const config = require('../config/config');
- const db = {};
- const sequelize = new Sequelize(
- config.db.database,
- config.db.user,
- config.db.password,
- config.db.options
- );
- fs.readdirSync(__dirname)
- .filter((file) => {
- file !== 'index.js'
- })
- .forEach((file) => {
- const model = sequelize.import(path.join(__dirname, file));
- db[model.name] = model;
- });
- db.sequelize = sequelize;
- db.Sequelize = Sequelize;
- module.exports = db
- module.exports = (sequelize, DataTypes) => {
- sequelize.define('User', {
- email : {
- type : Sequelize.STRING,
- unique : true
- },
- password : Sequelize.STRING
- });
- }
- const {User} = require('../models');
- module.exports = {
- async register (req, res) {
- try {
- const user = await User.create(req.body);
- res.send(user.toJSON());
- } catch (err) {
- res.status(400).send({
- error: `This E-mail account is already in use${err}`,
- })
- }
- }
- }
- "error": "This E-mail account is already in useTypeError: Cannot read property 'create' of undefined"
- const AuthenticationController = require('./controllers/AuthenticationController');
- module.exports = (app) => {
- app.post('/register',
- AuthenticationController.register)
- };
- {
- ***
- "main": "index.js",
- "scripts": {
- "start": "nodemon src/app.js",
- "lint": "eslint src/**/*.js"
- },
- ***
- "dependencies": {
- "body-parser": "^1.18.3",
- "cors": "^2.8.4",
- "eslint": "^4.19.1",
- "express": "^4.16.3",
- "morgan": "^1.9.0",
- "nodemon": "^1.17.5",
- "sequelize": "^4.8.0",
- "sqlite3": "^3.1.8"
- },
- "devDependencies": {
- "eslint-config-standard": "^11.0.0",
- "eslint-plugin-import": "^2.12.0",
- "eslint-plugin-node": "^6.0.1",
- "eslint-plugin-promise": "^3.8.0",
- "eslint-plugin-standard": "^3.1.0"
- }
- }
- sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:242:13
Add Comment
Please, Sign In to add comment