UNPKG

tynode

Version:

A CLI to quickly scaffold a Node.js TypeScript boilerplate with Express, Mongoose, and more.

47 lines (46 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mainBoilerplate = void 0; const mainBoilerplate = () => { return [ `import dotenv from 'dotenv'`, `dotenv.config()`, ``, `const ENV = process.env`, `import mongoose from 'mongoose'`, `mongoose.connect(\`\${ENV.MONGO_URL}/\${ENV.DB}\`)`, ``, `.then(() => console.log(\`Database connected - \${ENV.DB}\`))`, ``, `.catch(() => {`, `\tconsole.log(\`Database connection failed - \${ENV.DB}\`)`, `})`, ``, `import express, { Request, Response } from 'express'`, `import morgan from 'morgan'`, `const app = express()`, `app.listen(ENV.PORT, () => console.log(\`Server is running on http://localhost:\${ENV.PORT}\`))`, ``, `import cors from 'cors'`, `app.use(cors({`, `\torigin: '*'`, `}))`, ``, `app.use(express.json())`, `app.use(express.urlencoded({ extended: false }))`, `app.use(morgan('dev'))`, ``, `app.get("/", (req: Request, res: Response) => {`, `\tres.send(\``, `\t\t<h1>CodingOtt</h1>`, `\t\t<p>Website: <a href="https://www.codingott.com" target="_blank">www.codingott.com</a></p>`, `\t\t<p>YouTube: <a href="https://www.youtube.com/@codingott?sub_confirmation=1" target="_blank">YouTube Channel</a> — Learn AI/ML, Web Development, DevOps & more</p>`, `\t\`)`, `})`, ``, `app.use((req: Request, res: Response) => {`, `\tres.status(404).json({ message: \`\${req.url} not found\` })`, `})` ].join("\n"); }; exports.mainBoilerplate = mainBoilerplate;