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 search text in string using php ?

29-10-2017 php search string search

How to convert html to pdf in Node js

12-03-2017 pdf convert html node js

Get next date from given date in javascript

06-03-2017 date javascript next date

How to find Angular Errors

06-03-2017 errors angularjs exceptionHandler

Send Mail in Node Js

21-02-2017 node js mail npm module