Menu Search

Javascript

How to implement inheritance in node.js modules?
https://stackoverflow.com/questions/16213495/how-to-implement-inheritance-in-node-js-modules
function BaseModel() {
this.Express = require('express');

this.bodyParser = require('body-parser');
this.app = this.Express();
this.app.use(this.bodyParser.json());


this.app.get("/", function(req, res) {
try {
res.sendFile(__dirname + "/html/index.html");
console.log("BaseModel");
} catch (e) {
console.log('Exception:?+e);
throw e;
}

});



this.app.listen(2000, function(a) {
console.log("Listening to port 2000");
});
}

BaseModel.prototype.fromID = function() {};

module.exports = BaseModel;

var BaseModel = require('./BaseModel');

function FileUploadModel() {
FileUploadModel.super_.apply(this, arguments);
this.multer = require('multer');

this.Storage = this.multer.diskStorage({
destination : function(req, file, callback) {
console.log('Uploading:? + file.originalname);
callback(null, "./Images");
},
filename : function(req, file, callback) {
callback(null, file.fieldname + "_" + Date.now() + "_" + file.originalname);
}
});

var upload = this.multer({
storage : this.Storage
}).array("fileUploader", 3); //Field name and max count

this.app.get("/FileUploadInfo", function(req, res) {
res.sendFile(__dirname + "/html/FileUpload.html");
console.log("FileUploadInfo");
});

this.app.post("/api/Upload", function(req, res) {
upload(req, res, function(err) {
if (err) {
//return res.end("Something went wrong!");
return res.sendFile(__dirname + "/html/error.html");
}
//return res.end("File uploaded sucessfully!.");
return res.sendFile(__dirname + "/html/sucess.html");
});
});
}

FileUploadModel.super_ = BaseModel;

FileUploadModel.prototype = Object.create(BaseModel.prototype, {
constructor : {
value : FileUploadModel,
enumerable : false
}
});
FileUploadModel.prototype.show = function(text) {
console.log(text);
};

module.exports = FileUploadModel;

Liste

Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste
Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste

Index

Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste
Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste

LetzteChance.Org - Links -

PDF/ZIP/Word