Use java script file client side and server side at a time in node js

node js
include
call
javascript

In node js there is a module called as vm, this module is used to call javacsript functions both server side and client side at a time. Install vm module by using "npm install vm" . 

If want to use vm module also install fs module. fs module is used to read the file. Install fs module by using "npm install fs" .

Below code for include external javascript file,

var fs = require('fs');
var vm = require('vm');

vm.runInThisContext(fs.readFileSync(__dirname + "/public/controllers/globalCalls.js"));
console.log(ShowAttachmentName('ekg'));

 

You might also like:

How to upload file by using request module

18-03-2017 request module node js

Change datepicker display format

06-03-2017 datepicker angular js

How to remove last / value from url in javascript

27-02-2017 array javascript last value

Call a function every second or 5 seconds in javascript

22-02-2017 setinterval function calling

Get random strings from given string In javascript

21-02-2017 javascript random string