- Chapter 1: Introduction
- Chapter 2: IBM NodeServer Generator
- Chapter 3: Cleaning the house
- Chapter 4: TypeScript and routing-controllers
- Chapter 5: MongoDB and Mongoose
- Chapter 6: Nodejs Streams
- Chapter 7: Amazon S3 and why memory streams aren't a silver bullet ?
- Chapter 8: Mocha, chai and istanbul
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Routing Controllers Annotations | |
import { JsonController, Get, Controller, Param, Post } from "routing-controllers"; | |
import { PetRepository } from "../repositories/PetRepository"; | |
import { IPet } from "../interfaces/IPet"; | |
import { Pet } from "../models/Pet"; | |
import { Readable } from "stream"; | |
@JsonController() | |
// Create a controller prefix for each end point | |
@Controller("/pets") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Get('/hello-world-streams') | |
async streams() { | |
// Get Mongodb cursor | |
const cursor = this.repository.getCursorToAllRecords(); | |
const promise = new Promise((resolve, reject) => { | |
cursor.on('data', doc => { | |
console.log(doc); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Routing Controllers Annotations | |
import { JsonController, Get, Controller, Param, Post } from "routing-controllers"; | |
import { PetRepository } from "../repositories/PetRepository"; | |
import { IPet } from "../interfaces/IPet"; | |
import { Pet } from "../models/Pet"; | |
@JsonController() | |
// Create a controller prefix for each end point | |
@Controller("/pets") | |
export class PetController { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Service } from "typedi"; | |
import { Query } from "mongoose"; | |
import { Pet } from "../models/Pet"; | |
@Service() | |
export class PetRepository { | |
async getRecords(): Promise <Pet> { | |
/** | |
* I'd like to get only fifty records and each record |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mongoose } from "../database/config"; | |
import { Document, Schema } from "mongoose"; | |
import { IPet } from '../interfaces/IPet'; | |
interface IPetModel extends IPet, Document { | |
} | |
const PetSchema: Schema = new Schema({ | |
'name': String, | |
'age': Number, | |
'createdAt': Date, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express = require("express"); | |
module.exports = (app) => { | |
const router = express.Router(); | |
app.use("/swagger/api", express.static("./public/swagger.yaml")); | |
app.use("/explorer", express.static("./public/swagger-ui")); | |
app.use(router); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (app) => { | |
const router = require('express').Router(); | |
router.get('/', (req, res, next) => { | |
res.json({ status: 'UP' }); | |
}); | |
app.use('/health', router); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "reflect-metadata"; // this shim is required | |
import { createExpressServer, useContainer } from "routing-controllers"; | |
import { Container } from "typedi"; | |
import log4js = require('log4js'); | |
require('appmetrics-dash').attach(); | |
require('appmetrics-prometheus').attach(); | |
const appName = require('./../package').name; | |
const logger = log4js.getLogger(appName); |