1
0
mirror of https://github.com/microsoft/TypeScript-Node-Starter.git synced 2025-11-09 20:37:26 +00:00

WIP - still need to use NO_DATABASE env var to safely avoid db errors

This commit is contained in:
Bowden
2018-01-10 09:28:58 -08:00
parent 324a6c8a82
commit 97b1939c38
3 changed files with 13 additions and 3 deletions

View File

@@ -13,6 +13,9 @@
"cSpell.words": [
"definitelytyped",
"reddit",
"subreddit"
"resave",
"signup",
"subreddit",
"xframe"
]
}

View File

@@ -36,7 +36,7 @@ mongoose.connect(mongoUrl, {useMongoClient: true}).then(
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
).catch(err => {
console.log("MongoDB connection error. Please make sure MongoDB is running. " + err);
// process.exit();
process.exit();
});
// Express configuration

View File

@@ -5,13 +5,20 @@ import * as fs from "fs";
if (fs.existsSync(".env")) {
logger.debug("Using .env file to supply config environment variables");
dotenv.config({ path: ".env" });
} else {
} else if (fs.existsSync(".env.example")) {
logger.debug("Using .env.example file to supply config environment variables");
dotenv.config({ path: ".env.example" }); // you can delete this after you create your own .env file!
} else {
logger.error("This project requires a .env file to configure environment variables");
}
export const ENVIRONMENT = process.env.NODE_ENV;
const prod = ENVIRONMENT === "production"; // Anything else is treated as 'dev'
// Delete this after you've added a database to the project
if (process.env["NO_DATABASE_SETUP"] === "true") {
logger.debug(`No database detected. Either follow steps in the README to set up a MongoDB,
or delete the NO_DATABASE_SETUP setting from your .env settings file if you already have one setup.`);
}
export const SESSION_SECRET = process.env["SESSION_SECRET"];
export const MONGODB_URI = prod ? process.env["MONGODB_URI"] : process.env["MONGODB_URI_LOCAL"];