From 750121489e79daee35bced86891e222829648eae Mon Sep 17 00:00:00 2001 From: "saravanakumar.arumugam" Date: Sat, 1 Jun 2024 02:26:38 +0530 Subject: [PATCH] Basic changes are made --- templates/js/app.js.ejs | 14 ++++++++------ templates/js/routes/index.js | 12 +++++++++--- templates/js/routes/users.js | 12 +++++++++--- templates/js/www.ejs | 18 +++++++++--------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/templates/js/app.js.ejs b/templates/js/app.js.ejs index 2ef75aec..c36c6044 100644 --- a/templates/js/app.js.ejs +++ b/templates/js/app.js.ejs @@ -1,17 +1,19 @@ +'use strict'; + <% if (view) { -%> -var createError = require('http-errors'); +const createError = require('http-errors'); <% } -%> -var express = require('express'); -var path = require('path'); +const express = require('express'); +const path = require('path'); <% Object.keys(modules).sort().forEach(function (variable) { -%> -var <%- variable %> = require('<%- modules[variable] %>'); +const <%- variable %> = require('<%- modules[variable] %>'); <% }); -%> <% Object.keys(localModules).sort().forEach(function (variable) { -%> -var <%- variable %> = require('<%- localModules[variable] %>'); +const <%- variable %> = require('<%- localModules[variable] %>'); <% }); -%> -var app = express(); +const app = express(); <% if (view) { -%> // view engine setup diff --git a/templates/js/routes/index.js b/templates/js/routes/index.js index ecca96a5..8510baa8 100644 --- a/templates/js/routes/index.js +++ b/templates/js/routes/index.js @@ -1,9 +1,15 @@ -var express = require('express'); -var router = express.Router(); +'use strict'; + +const express = require('express'); +const router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { - res.render('index', { title: 'Express' }); + try { + return res.render('index', { title: 'Express' }); + } catch (error) { + next(error); + } }); module.exports = router; diff --git a/templates/js/routes/users.js b/templates/js/routes/users.js index 623e4302..7fef834a 100644 --- a/templates/js/routes/users.js +++ b/templates/js/routes/users.js @@ -1,9 +1,15 @@ -var express = require('express'); -var router = express.Router(); +'use strict'; + +const express = require('express'); +const router = express.Router(); /* GET users listing. */ router.get('/', function(req, res, next) { - res.send('respond with a resource'); + try { + return res.send('respond with a resource'); + } catch (error) { + next(error); + } }); module.exports = router; diff --git a/templates/js/www.ejs b/templates/js/www.ejs index 690fc488..a309083e 100644 --- a/templates/js/www.ejs +++ b/templates/js/www.ejs @@ -4,22 +4,22 @@ * Module dependencies. */ -var app = require('../app'); -var debug = require('debug')('<%- name %>:server'); -var http = require('http'); +const app = require('../app'); +const debug = require('debug')('<%- name %>:server'); +const http = require('http'); /** * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || '3000'); +const port = normalizePort(process.env.PORT || '3000'); app.set('port', port); /** * Create HTTP server. */ -var server = http.createServer(app); +const server = http.createServer(app); /** * Listen on provided port, on all network interfaces. @@ -34,7 +34,7 @@ server.on('listening', onListening); */ function normalizePort(val) { - var port = parseInt(val, 10); + const port = parseInt(val, 10); if (isNaN(port)) { // named pipe @@ -58,7 +58,7 @@ function onError(error) { throw error; } - var bind = typeof port === 'string' + const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; @@ -82,8 +82,8 @@ function onError(error) { */ function onListening() { - var addr = server.address(); - var bind = typeof addr === 'string' + const addr = server.address(); + const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; debug('Listening on ' + bind);