Skip to content

Commit

Permalink
Import dotenv, create .env file from template if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhorsford committed Apr 28, 2017
1 parent be668ae commit 3c19575
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/template.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# =========================================
# WARNING: Don't commit this file to git
# =========================================
#
# Use this file for storing private data - things like API keys and admin credentials
#
# Storing data:
#
# EXAMPLE_API_KEY=123456789
# JSON={"foo": "bar"}
#
# More examples here: https://www.npmjs.com/package/dotenv
#
# Use the data in your app:
#
# var key = process.env.EXAMPLE_API_KEY

# =========================================
# INSERT YOUR DATA HERE:

2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var dotenv = require('dotenv').config()
require('dotenv').config()
var crypto = require('crypto')
var path = require('path')
var express = require('express')
Expand Down
12 changes: 11 additions & 1 deletion start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
var path = require('path')
var fs = require('fs')

if (!fs.existsSync(path.join(__dirname, '/node_modules'))) {
// Check if node_modules folder exists
const nodeModulesExists = fs.existsSync(path.join(__dirname, '/node_modules'))
if (!nodeModulesExists) {
console.error('ERROR: Node module folder missing. Try running `npm install`')
process.exit(0)
}

// Create template .env file if it doesn't exist
const envExists = fs.existsSync(path.join(__dirname, '/.env'))
if (!envExists) {
console.log('Creating template .env file')
fs.createReadStream(path.join(__dirname, '/lib/template.env'))
.pipe(fs.createWriteStream(path.join(__dirname, '/.env')))
}

// run gulp

var spawn = require('cross-spawn')
Expand Down

0 comments on commit 3c19575

Please sign in to comment.