Jelajahi Sumber

add color of console.log

maguohua 7 tahun lalu
induk
melakukan
307351c57b
5 mengubah file dengan 25 tambahan dan 8 penghapusan
  1. TEMPAT SAMPAH
      .DS_Store
  2. 11 3
      .gitignore
  3. 3 2
      app.js
  4. 10 3
      mongodb/db.js
  5. 1 0
      package.json

TEMPAT SAMPAH
.DS_Store


+ 11 - 3
.gitignore

@@ -1,4 +1,12 @@
-npm-debug.log
-node_modules
+/node_modules
 coverage
-package-lock.json
+package-lock.json
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*

+ 3 - 2
app.js

@@ -9,6 +9,7 @@ import winston from 'winston';
 import expressWinston from 'express-winston';
 import path from 'path';
 import history from 'connect-history-api-fallback';
+import chalk from 'chalk';
 // import Statistic from './middlewares/statistic'
 
 const app = express();
@@ -30,13 +31,13 @@ app.all('*', (req, res, next) => {
 const MongoStore = connectMongo(session);
 app.use(cookieParser());
 app.use(session({
-	  	name: config.session.name,
+	  name: config.session.name,
 		secret: config.session.secret,
 		resave: true,
 		saveUninitialized: false,
 		cookie: config.session.cookie,
 		store: new MongoStore({
-	  	url: config.url
+	  url: config.url
 	})
 }))
 

+ 10 - 3
mongodb/db.js

@@ -2,22 +2,29 @@
 
 import mongoose from 'mongoose';
 import config from 'config-lite';
+import chalk from 'chalk';
 mongoose.connect(config.url, {useMongoClient:true});
 mongoose.Promise = global.Promise;
 
 const db = mongoose.connection;
 
 db.once('open' ,() => {
-	console.log('连接数据库成功');
+	console.log(
+    chalk.green('连接数据库成功')
+  );
 })
 
 db.on('error', function(error) {
-    console.error('Error in MongoDb connection: ' + error);
+    console.error(
+      chalk.red('Error in MongoDb connection: ' + error)
+    );
     mongoose.disconnect();
 });
 
 db.on('close', function() {
-    console.log('数据库断开,重新连接数据库');
+    console.log(
+      chalk.red('数据库断开,重新连接数据库')
+    );
     mongoose.connect(config.url, {server:{auto_reconnect:true}});
 });
 

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
     "babel-register": "^6.24.0",
     "bluebird": "^3.5.0",
     "captchapng": "0.0.1",
+    "chalk": "^2.3.0",
     "config-lite": "^1.5.0",
     "connect-flash": "^0.1.1",
     "connect-history-api-fallback": "^1.3.0",