need help in adding node.js modules in custom widget

1055
7
03-13-2017 03:37 PM
sapnas
by
Occasional Contributor III

Is it possible to load node.js module in dojo framework used for building custom widget? Any sample code is greatly appreciated.

0 Kudos
7 Replies
thejuskambi
Regular Contributor

Can you be more specific. Also which version of JS Api are you using?

If it is about just requiring nodejs module in AMD. you can do it like below. 

// This:
var fs = require("fs");

// Would become:
require([ "dojo/node!fs" ], function(fs){
    // Utilise the "fs" module
});

Complete details can be found here Dojo and Node.js - Dojo Toolkit Tutorial 

Hope this was helpful.

sapnas
by
Occasional Contributor III

 how do you incorporate the logic in widget.js?

define

([

...

'dojo/node!fs'],

function(.....,fs)

{

somefunction:function(){

fs.readFile("MyFile.json", function (err, data) {

if (err) alert("error");

});

}

});

});

I understand it is a client side script but the apps are stored in server folder once created through webappbuilder. I just need a way to manipulate the apps during runtime. I'm currently using a mixed bag with service to manipulate  app on iis while the client apps  on nodejs.

0 Kudos
PrashantKirpan
Occasional Contributor

Hi Sapna,

I am trying to implement the same but no luck. Did you find any other way around?

I am also trying to store custom widget's run time settings into custom_config.json.

Any help would be appreciated.

Regards,

Prashant 

0 Kudos
sapnas
by
Occasional Contributor III

I ended up using .net Web api rest services in my web app builder widgets. 

0 Kudos
DávidGregor
New Contributor II

The widget cannot load "dojo/node!fs" for me, even if i define('dojo/require'). I'm working in WAB environment. Could you give me a workaround?

Thank you!

0 Kudos
JinGao
by
New Contributor

I have the same problem to load "dojo/node!fs". I got an error message with "cannot find node.js require" . does anyone has a solution to this issue? Thanks!

 

0 Kudos
diaconori
New Contributor III

Same problem here. I've tried to load SheetJS, ExcelJS, file-saver.js, and so many others, just for a simple use case of trying to export my excel document to the user. 

There's ZERO documentation from Dojo on how to utilitize your node modules that you install in your widget (im using js api 3.x)

0 Kudos