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 redirect one page to another page in php

20-03-2017 redirect php

How to make an http request in node js

14-03-2017 http module node js

Convert Time 24 hrs to 12 hrs format In javascript

12-03-2017 date javascript 12hrs convert

Remove last two characters from given string

06-03-2017 substring javascript remove

Email validation regular expression in javascript

22-02-2017 email validation regex