How does exporting the express instance work
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I've came across code that goes like this app = module.exports = express()
app = express()
app.get('/blah', function(a,b){});
app.post('/blah', function(a,b){});
module.exports = app
function createServer() {
//the magic happens in the next line:
function app(req, res, next){ app.handle(req, res, next); }
utils.merge(app, proto);
utils.merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
for (var i = 0; i < arguments.length; ++i) {
app.use(arguments[i]);
}
return app;
};
|
Separating logic from Express router and still access Express functions
Date : March 29 2020, 07:55 AM
To fix this issue req and res are just ordinary objects passed as arguments to the controller function. You don't have to require anything special in Parent.controller.js. Just make sure the parameters for createChild are req, res. And next if you needed. Like so: module.exports.createChild = (req, res, next) => {
res.status(200).json({ message: 'OK' });
}
const express = require('express');
const Parent = require('Parent.controller');
const router = express.Router();
Router.post('/create-child', Parent.createChild);
|
Exporting and importing Express modules
Date : March 29 2020, 07:55 AM
it helps some times You can export the friends array from your friends.js module like this: // array of objects
const friends = [
{
routeName: "ahmed",
name:"Ahmed",
photourl:"https://media.licdn.com/mpr/mpr/shrinknp_400_400/p/6/005/064/1bd/3435aa3.jpg",
questions:[
5,
1,
4,
4,
5,
1,
2,
5,
4,
1
]
}
];
module.exports = function(app){
//retreiving stored objects with person's data
app.post("/survey", function(req, res){
var incomingPerson = req.body;
incomingPerson.routeName = incomingPerson.name.replace(/\s+/g, "").toLowerCase();
console.log(incomingPerson);
// friends.push(person);
});
return friends;
};
module.exports.friends = friends;
const friends = require('./friends.js').friends;
|
Exporting Ladder Logic in Tia 14
Date : March 29 2020, 07:55 AM
this will help Your third option you listed may be the best way to do this. You can use the Openness API that is a .net dll. You can quite easily export a plc block (in xml) then import the function block into another project. you don't even have to look at the xml to do this. Here is an example code of how to do so //Import blocks
private static void ImportBlocks(PlcSoftware plcSoftware)
{
PlcBlockGroup blockGroup = plcSoftware.BlockGroup;
IList<PlcBlock> blocks = blockGroup.Blocks.Import(new
FileInfo(@"D:\Blocks\myBlock.xml"), ImportOptions.Override);
}
private static void ExportBlock(PlcSoftware plcSoftware)
{
PlcBlock plcBlock = plcSoftware.BlockGroup.Blocks.Find("MyBlock");
plcBlock.Export(new FileInfo(string.Format(@”D:\Samples\{0}.xml”,
plcBlock.Name)),
ExportOptions.WithDefaults);
}
|
Exporting and importing in Node express
Date : March 29 2020, 07:55 AM
this one helps. In your .js file, you can export whatever functions you would like to use in other parts of your code base. The below is an example of what should go at the bottom of your .js file. It will export the 3 functions you defined. module.exports = {
findByEmail,
updateUser,
deleteUser
}
const commonMethods = require('./commonMethods.js')
|