Skip to content

Commit 16e34ff

Browse files
authored
updated tslint rules, added pm2 (#9)
1 parent fdc8825 commit 16e34ff

File tree

9 files changed

+42
-24
lines changed

9 files changed

+42
-24
lines changed

Readme.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ If you found this project useful, then please consider giving it a ⭐️ on Git
3838
create a database with the name `node-typescript-rest-api` and then run/ import the `.sql` files (extract the sql files from sql.zip).
3939
Or you can run `npm run seed`.
4040

41+
4. install `pm2` globally with `npm install -g pm2`
42+
4143
### Run the app locally
4244

4345
- git clone https://github.com/nmanikiran/rest-api-node-typescript.git
4446

4547
- `npm install`
4648
- `npm start` - This will start the application and run on port 3000
4749
- `npm run dev` - This will start the application in development mode
50+
- `npm run watch & pm2 start ecosystem.config.js` to start the application with cluster for scalability
4851

4952
you can change port in `.env` file check `.env-sample`
5053

ecosystem.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
name: "API",
5+
script: "server.js",
6+
instances: 2,
7+
watch: true,
8+
autostart: true,
9+
max_memory_restart: "1G",
10+
env: { NODE_ENV: "development" },
11+
env_production: { NODE_ENV: "development" },
12+
},
13+
],
14+
};

server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import Server from './src/index';
77

88
const app: Application = express();
99
const server: Server = new Server(app);
10-
const port: number = parseInt(process.env.port, 10) || 3000;
10+
const port: number = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
1111

1212
app.listen(port, 'localhost', function () {
1313
console.info(`Server running on : http://localhost:${port}`);
1414
}).on('error', (err: any) => {
1515
if (err.code === 'EADDRINUSE') {
1616
console.log('server startup error: address already in use');
17-
}
18-
else {
17+
} else {
1918
console.log(err);
2019
}
2120
});

src/controllers/CoursesCtrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class CoursesCtrl {
77

88
async getAllCourses(req: Request, res: Response, next: NextFunction) {
99
try {
10-
const courseList = await CourseRepo.getAllCourses({ order: ['seqNo'] })
10+
const courseList = await CourseRepo.getAllCourses({ order: ['seqNo'] });
1111
res.json(courseList);
1212
} catch (error) {
1313
apiErrorHandler(error, req, res, 'Fetch All Courses failed.');

src/db/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Sequelize, Options } from 'sequelize';
2-
const dbUrl: string = process.env.DB_URL;
3-
const nodeEnv: string = process.env.NODE_ENV;
2+
const dbUrl: string = process.env.DB_URL || '';
3+
const nodeEnv: string = process.env.NODE_ENV || '';
44

55
if (!dbUrl) {
66
console.log('Please create .env file, refer .env.sample');

src/models/Course.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { Lesson } from './Lesson';
44

55
export class Course extends Model {
66
public id!: number;
7-
public description: string;
8-
public url: string;
9-
public longDescription: string;
10-
public iconUrl: string;
11-
public tags: string;
12-
public channelTitle: string;
13-
public channelUrl: string;
14-
public channelId: string;
15-
public seqNo: number;
7+
public description!: string;
8+
public url!: string;
9+
public longDescription!: string;
10+
public iconUrl!: string;
11+
public tags!: string;
12+
public channelTitle!: string;
13+
public channelUrl!: string;
14+
public channelId!: string;
15+
public seqNo!: number;
1616
}
1717

1818
Course.init(

src/models/Lesson.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Model, DataTypes } from 'sequelize';
33

44
export class Lesson extends Model {
55
public id!: number;
6-
public url: string;
7-
public title: string;
8-
public description: string;
9-
public thumbnailUrl: string;
10-
public duration: string;
11-
public seqNo: number;
12-
public courseId: number;
6+
public url!: string;
7+
public title!: string;
8+
public description!: string;
9+
public thumbnailUrl!: string;
10+
public duration!: string;
11+
public seqNo!: number;
12+
public courseId!: number;
1313
}
1414

1515
Lesson.init(

src/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Application } from 'express';
22
import courseRouter from './CourseRoutes';
3-
import lessonRouter from './LessonRoutes'
3+
import lessonRouter from './LessonRoutes';
44

55
export default class Routes {
66

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"module": "commonjs",
44
"target": "es6",
55
"noImplicitAny": false,
6-
"sourceMap": true
6+
"sourceMap": true,
7+
"strict": true,
8+
"allowJs": false
79
},
810
"files.exclude": {
911
"**/.git": true,

0 commit comments

Comments
 (0)