removed error test log and added db creation
This commit is contained in:
parent
7394758d27
commit
10c6fb611f
3 changed files with 33 additions and 8 deletions
|
@ -25,12 +25,11 @@ function LoggerConfig () {
|
|||
});
|
||||
// test all the log levels
|
||||
logger.info('testing winston log levels...');
|
||||
logger.error('Level 0');
|
||||
logger.warn('Level 1');
|
||||
logger.info('Level 2');
|
||||
logger.verbose('Level 3');
|
||||
logger.debug('Level 4');
|
||||
logger.silly('Level 5');
|
||||
logger.warn('Testing: Log Level 1');
|
||||
logger.info('Testing: Log Level 2');
|
||||
logger.verbose('Testing: Log Level 3');
|
||||
logger.debug('Testing: Log Level 4');
|
||||
logger.silly('Testing: Log Level 5');
|
||||
};
|
||||
};
|
||||
|
||||
|
|
8
index.js
8
index.js
|
@ -13,6 +13,7 @@ const loggerConfig = require('./config/loggerConfig.js');
|
|||
const mysqlConfig = require('./config/mysqlConfig.js');
|
||||
const siteConfig = require('./config/siteConfig.js');
|
||||
const slackConfig = require('./config/slackConfig.js');
|
||||
const createDatabaseIfNotExists = require('./server/models/utils/createDatabaseIfNotExists.js');
|
||||
|
||||
function Server () {
|
||||
this.configureLogger = loggerConfig.update;
|
||||
|
@ -81,8 +82,11 @@ function Server () {
|
|||
const db = require('./server/models');
|
||||
const PORT = siteConfig.details.port;
|
||||
// sync sequelize
|
||||
db.sequelize.sync()
|
||||
// start the server
|
||||
createDatabaseIfNotExists()
|
||||
.then(() => {
|
||||
db.sequelize.sync()
|
||||
})
|
||||
// start the server
|
||||
.then(() => {
|
||||
this.server.listen(PORT, () => {
|
||||
logger.info(`Server is listening on PORT ${PORT}`);
|
||||
|
|
22
server/models/utils/createDatabaseIfNotExists.js
Normal file
22
server/models/utils/createDatabaseIfNotExists.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const Sequelize = require('sequelize');
|
||||
|
||||
const createDatabaseIfNotExists = () => {
|
||||
const {database, username, password} = require('../../../config/mysqlConfig.js');
|
||||
const sequelize = new Sequelize('', username, password, {
|
||||
dialect : 'mysql',
|
||||
logging : true,
|
||||
operatorsAliases: false,
|
||||
});
|
||||
console.log('username:', username, 'password:', password);
|
||||
return new Promise((resolve, reject) => {
|
||||
sequelize.query(`CREATE DATABASE IF NOT EXISTS ${database};`)
|
||||
.then(() => {
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = createDatabaseIfNotExists;
|
Loading…
Reference in a new issue