From 01097385d6de405748bd4154b4c7a16a827b76f4 Mon Sep 17 00:00:00 2001 From: Bouncey Date: Fri, 9 Nov 2018 16:07:52 +0000 Subject: [PATCH] fix: Add 'production' check --- tools/scripts/seed/seedNewsArticles.js | 46 ++++++++++++++------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/tools/scripts/seed/seedNewsArticles.js b/tools/scripts/seed/seedNewsArticles.js index 5e4c386d75..0733574b1c 100644 --- a/tools/scripts/seed/seedNewsArticles.js +++ b/tools/scripts/seed/seedNewsArticles.js @@ -9,7 +9,7 @@ const debug = require('debug'); const log = debug('fcc:tools:seedNewsArticles'); -const { MONGOHQ_URL } = process.env; +const { MONGOHQ_URL, NODE_ENV: env } = process.env; function handleError(err, client) { if (err) { @@ -26,30 +26,32 @@ function handleError(err, client) { } } -MongoClient.connect( - MONGOHQ_URL, - { useNewUrlParser: true }, - async function(err, client) { - handleError(err, client); +if (env !== 'production') { + MongoClient.connect( + MONGOHQ_URL, + { useNewUrlParser: true }, + async function(err, client) { + handleError(err, client); - log('Connected successfully to mongo'); - const db = client.db('freecodecamp'); - const articleCollection = db.collection('article'); + log('Connected successfully to mongo'); + const db = client.db('freecodecamp'); + const articleCollection = db.collection('article'); - const articles = stubArticles(200); + const articles = stubArticles(200); - await articleCollection - .deleteMany({}) - .catch(err => handleError(err, client)); - return articleCollection - .insertMany(articles) - .then(({ insertedCount }) => { - log('inserted %d new articles', insertedCount); - client.close(); - }) - .catch(err => handleError(err, client)); - } -); + await articleCollection + .deleteMany({}) + .catch(err => handleError(err, client)); + return articleCollection + .insertMany(articles) + .then(({ insertedCount }) => { + log('inserted %d new articles', insertedCount); + client.close(); + }) + .catch(err => handleError(err, client)); + } + ); +} function stubArticles(numberOfArticles = 1) { return new Array(numberOfArticles).fill('').map(() => generateArticle());