diff --git a/templates/app.js b/templates/app.js index b9acb03..d75bcc6 100644 --- a/templates/app.js +++ b/templates/app.js @@ -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'; @@ -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'); diff --git a/templates/bin/www.js b/templates/bin/www.js index 58fe567..d71f669 100644 --- a/templates/bin/www.js +++ b/templates/bin/www.js @@ -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) => {