Skip to content

updated tslint rules, added pm2 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ If you found this project useful, then please consider giving it a ⭐️ on Git
create a database with the name `node-typescript-rest-api` and then run/ import the `.sql` files (extract the sql files from sql.zip).
Or you can run `npm run seed`.

4. install `pm2` globally with `npm install -g pm2`

### Run the app locally

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

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

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

Expand Down
14 changes: 14 additions & 0 deletions ecosystem.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
apps: [
{
name: "API",
script: "server.js",
instances: 2,
watch: true,
autostart: true,
max_memory_restart: "1G",
env: { NODE_ENV: "development" },
env_production: { NODE_ENV: "development" },
},
],
};
5 changes: 2 additions & 3 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import Server from './src/index';

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

app.listen(port, 'localhost', function () {
console.info(`Server running on : http://localhost:${port}`);
}).on('error', (err: any) => {
if (err.code === 'EADDRINUSE') {
console.log('server startup error: address already in use');
}
else {
} else {
console.log(err);
}
});
2 changes: 1 addition & 1 deletion src/controllers/CoursesCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class CoursesCtrl {

async getAllCourses(req: Request, res: Response, next: NextFunction) {
try {
const courseList = await CourseRepo.getAllCourses({ order: ['seqNo'] })
const courseList = await CourseRepo.getAllCourses({ order: ['seqNo'] });
res.json(courseList);
} catch (error) {
apiErrorHandler(error, req, res, 'Fetch All Courses failed.');
Expand Down
4 changes: 2 additions & 2 deletions src/db/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Sequelize, Options } from 'sequelize';
const dbUrl: string = process.env.DB_URL;
const nodeEnv: string = process.env.NODE_ENV;
const dbUrl: string = process.env.DB_URL || '';
const nodeEnv: string = process.env.NODE_ENV || '';

if (!dbUrl) {
console.log('Please create .env file, refer .env.sample');
Expand Down
18 changes: 9 additions & 9 deletions src/models/Course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { Lesson } from './Lesson';

export class Course extends Model {
public id!: number;
public description: string;
public url: string;
public longDescription: string;
public iconUrl: string;
public tags: string;
public channelTitle: string;
public channelUrl: string;
public channelId: string;
public seqNo: number;
public description!: string;
public url!: string;
public longDescription!: string;
public iconUrl!: string;
public tags!: string;
public channelTitle!: string;
public channelUrl!: string;
public channelId!: string;
public seqNo!: number;
}

Course.init(
Expand Down
14 changes: 7 additions & 7 deletions src/models/Lesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Model, DataTypes } from 'sequelize';

export class Lesson extends Model {
public id!: number;
public url: string;
public title: string;
public description: string;
public thumbnailUrl: string;
public duration: string;
public seqNo: number;
public courseId: number;
public url!: string;
public title!: string;
public description!: string;
public thumbnailUrl!: string;
public duration!: string;
public seqNo!: number;
public courseId!: number;
}

Lesson.init(
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Application } from 'express';
import courseRouter from './CourseRoutes';
import lessonRouter from './LessonRoutes'
import lessonRouter from './LessonRoutes';

export default class Routes {

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": true
"sourceMap": true,
"strict": true,
"allowJs": false
},
"files.exclude": {
"**/.git": true,
Expand Down