Answer the question
In order to leave comments, you need to log in
How to add your own method to the Express() module using util?
Hello. I'm trying to extend the module express
and add my method there.
In general, the util module was used for this.
My piece of code:
var expressApplication = require('express');
var util = require('util');
function Application() {
expressApplication.apply(this, arguments);
this.handlers = {};
}
util.inherits(Application, expressApplication);
//добавление своего метода
Application.prototype.write = function(data) {
console.log(data)
};
var app = new Application();
//проверяем наследование
console.log(app instanceof expressApplication); // true
console.log(Application.super_ === expressApplication); // true
//проверяем мои методы
console.log(app.write('test'));
console.log(app.use)
says this with an error, app.use is not a function
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question