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

30-07-2017 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:

Detect AdBlock with JavaScript in my browser
30-07-2017 AdBlock javascript detect
How to use request module in node js
16-03-2017 request module node js
How to use http-post request in node js
14-03-2017 http-post module node js
Email validation regular expression in javascript
22-02-2017 email validation regex
Get Unique values from array/object in javascript
19-02-2017 javascript unique remove repeated values from array