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:

Functions in javascript

25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions.

How to submit form using javascript or jquery.

16-04-2017 javascript jquery submit form

Sanitization in java sript

14-03-2017 sanitization java script

Get random strings from given string In javascript

21-02-2017 javascript random string

Send Mail in Node Js

21-02-2017 node js mail npm module