I have a basic express app, where app.ts looks like
import * as express from "express";
const application: express.Application = express();
application.get("/", function(
request: express.Request,
response: express.Response
) {
console.log("Inside Router ");
response.json({ "test": true});
});
application.listen(3000, function() {
console.log("sever ready");
});
In this case, the console message "Inside Route" is printed in server console when the route is hit.
However,
wrapper.ts
const methods = () => {
};
console.log("This is a testable offence");
export const wrapperMethod = {methods};
const express = require('express');
const wrapper = require('./wrapper');
const application = express();
application.get("/city", function(
request,
response
) {
console.log("when");
let results = {};
let test = wrapper.methods();
response.json(results);
});
application.listen(3000, function() {
console.log("sever ready");
});
NPM COMMAND:
nodemon ts-node ./src/index.ts
In this case, on server start, we can observe "This is a testable offence" is being printed.
But the message "Inside Route" is only printed when the route is hit.
can anyone explain the reason for the same ?
Short answer: