create-express-kickstart 1.1.0 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js CHANGED
@@ -71,6 +71,9 @@ async function init() {
71
71
  : 'npm';
72
72
 
73
73
  const initGit = (await question('\nšŸ‘‰ Initialize a git repository? [Y/n] ')).toLowerCase() !== 'n';
74
+ const initDocker = (await question('šŸ‘‰ Include Dockerfile & docker-compose.yml? [Y/n] ')).toLowerCase() !== 'n';
75
+ const initAuth = (await question('šŸ‘‰ Include basic JWT Auth boilerplate? [Y/n] ')).toLowerCase() !== 'n';
76
+ const useESM = (await question('šŸ‘‰ Use ECMAScript Modules (ESM) over CommonJS? [Y/n] ')).toLowerCase() !== 'n';
74
77
 
75
78
  rl.close();
76
79
 
@@ -111,6 +114,44 @@ async function init() {
111
114
  fs.copyFileSync(envExamplePath, path.join(projectPath, '.env'));
112
115
  }
113
116
 
117
+ if (initDocker) {
118
+ console.log(`🐳 Adding Docker files...`);
119
+ const dockerfilePath = path.join(__dirname, '..', 'templates', 'Dockerfile');
120
+ const dockerComposePath = path.join(__dirname, '..', 'templates', 'docker-compose.yml');
121
+
122
+ // Fallbacks if templates aren't bundled right
123
+ if (fs.existsSync(dockerfilePath)) fs.copyFileSync(dockerfilePath, path.join(projectPath, 'Dockerfile'));
124
+ if (fs.existsSync(dockerComposePath) && deps.mongoose) {
125
+ fs.copyFileSync(dockerComposePath, path.join(projectPath, 'docker-compose.yml'));
126
+ }
127
+ }
128
+
129
+ if (initAuth) {
130
+ console.log(`šŸ” Adding Auth templates...`);
131
+ // Need to ensure directories exist
132
+ fs.mkdirSync(path.join(projectPath, 'src', 'controllers'), { recursive: true });
133
+ fs.mkdirSync(path.join(projectPath, 'src', 'middlewares'), { recursive: true });
134
+ fs.mkdirSync(path.join(projectPath, 'src', 'routes'), { recursive: true });
135
+
136
+ // Copy the templates
137
+ fs.copyFileSync(
138
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.controller.js'),
139
+ path.join(projectPath, 'src', 'controllers', 'auth.controller.js')
140
+ );
141
+ fs.copyFileSync(
142
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.middleware.js'),
143
+ path.join(projectPath, 'src', 'middlewares', 'auth.middleware.js')
144
+ );
145
+ fs.copyFileSync(
146
+ path.join(__dirname, '..', 'templates', 'auth', 'auth.routes.js'),
147
+ path.join(projectPath, 'src', 'routes', 'auth.routes.js')
148
+ );
149
+
150
+ // Append JWT secret to env example
151
+ fs.appendFileSync(path.join(projectPath, '.env.example'), '\nJWT_SECRET=supersecretjwtkey123\n');
152
+ fs.appendFileSync(path.join(projectPath, '.env'), '\nJWT_SECRET=supersecretjwtkey123\n');
153
+ }
154
+
114
155
  // 3. Create package.json
115
156
  console.log(`šŸ“¦ Setting up package.json...`);
116
157
  const packageJsonTemplate = {
@@ -118,7 +159,7 @@ async function init() {
118
159
  version: "1.0.0",
119
160
  description: description || "A production-ready Node.js Express API",
120
161
  main: "src/server.js",
121
- type: "module",
162
+ type: useESM ? "module" : "commonjs",
122
163
  scripts: {
123
164
  "start": "node src/server.js",
124
165
  "dev": "nodemon src/server.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-express-kickstart",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "description": "Production-ready CLI starter for Express APIs",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {
@@ -0,0 +1,20 @@
1
+ # Use official Node.js runtime as a parent image
2
+ FROM node:20-alpine
3
+
4
+ # Set working directory inside the container
5
+ WORKDIR /usr/src/app
6
+
7
+ # Copy package.json and lockfile based on package manager used
8
+ COPY package.json ./
9
+
10
+ # Install project dependencies
11
+ RUN npm install --production
12
+
13
+ # Bundle app source
14
+ COPY . .
15
+
16
+ # Expose port the app runs on
17
+ EXPOSE 3000
18
+
19
+ # Command to run your app
20
+ CMD [ "node", "src/server.js" ]
@@ -0,0 +1,5 @@
1
+ export const authController = {
2
+ login: (req, res) => res.json({ message: "Login logic goes here." }),
3
+ register: (req, res) => res.json({ message: "Register logic goes here." }),
4
+ profile: (req, res) => res.json({ message: "Protected profile data." })
5
+ };
@@ -0,0 +1,5 @@
1
+ export const authMiddleware = (req, res, next) => {
2
+ // Add JWT verification logic here
3
+ console.log('Verifying token...');
4
+ next();
5
+ };
@@ -0,0 +1,11 @@
1
+ import { Router } from 'express';
2
+ import { authController } from '../controllers/auth.controller.js';
3
+ import { authMiddleware } from '../middlewares/auth.middleware.js';
4
+
5
+ const router = Router();
6
+
7
+ router.post('/login', authController.login);
8
+ router.post('/register', authController.register);
9
+ router.get('/profile', authMiddleware, authController.profile);
10
+
11
+ export default router;
@@ -0,0 +1,26 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ app:
5
+ build: .
6
+ ports:
7
+ - "3000:3000"
8
+ environment:
9
+ - NODE_ENV=development
10
+ - PORT=3000
11
+ - MONGO_URI=mongodb://mongo:27017/express-api
12
+ volumes:
13
+ - .:/usr/src/app
14
+ - /usr/src/app/node_modules
15
+ depends_on:
16
+ - mongo
17
+
18
+ mongo:
19
+ image: mongo:latest
20
+ ports:
21
+ - "27017:27017"
22
+ volumes:
23
+ - mongo-data:/data/db
24
+
25
+ volumes:
26
+ mongo-data: