Skip to content

Commit

Permalink
fix: dotenv with debug
Browse files Browse the repository at this point in the history
- by using debugFactory.debug as described here debug-js/debug#446 (comment)
  • Loading branch information
iwaduarte committed Oct 13, 2022
1 parent 9290465 commit 3bf94c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 2 additions & 4 deletions templates/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
`${
opts.esm
? `import * as dotenv from 'dotenv';
dotenv.config();
import createError from 'http-errors';
? `import createError from 'http-errors';
import express from 'express';
import cookieParser from 'cookie-parser';
import logger from 'morgan';
Expand All @@ -12,7 +10,7 @@ ${opts.helmet ? `import helmet from 'helmet';` : ``}
import mainRouter from './routes/routes.js';
${opts.sequelize ? "import usersRouter from './routes/users.js';" : ''}
`
: `require('dotenv').config();
: `
const createError = require('http-errors');
const express = require('express');
const cookieParser = require('cookie-parser');
Expand Down
22 changes: 14 additions & 8 deletions templates/bin/www.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
${
opts.esm || ''
? `import app from '../app.js';
import _debug from 'debug';
? `import dotenv from "dotenv";
dotenv.config();
import app from '../app.js';
import debugFactory from 'debug';
import http from 'http';
const debug = _debug('${opts.projectName}:server');
`
: `const app = require('../app');
const debug = require('debug')('${opts.projectName}:server');
const http = require('http');`
}
: `require('dotenv').config();
const app = require('../app');
const debugFactory = require('debug')
const http = require('http');
`
}
const { DEBUG } = process.env;
debugFactory.enable(DEBUG);
const debug= debugFactory('${opts.projectName}:server');
/** Normalize a port into a number, string, or false. */
const normalizePort = (val) => {
Expand Down

0 comments on commit 3bf94c6

Please sign in to comment.