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:

A Very Big Sum | Javascript | hackerrank

07-05-2020 A Very Big Sum Javascript hackerrank

Check null values in JavaScript?

04-02-2019 JavaScript null check null value

File Upload Using Angular Js and Node Js

28-05-2018 AngularJs Node js file upload multer module

How to redirect one page to another page in php

20-03-2017 redirect php

Filters for convert text to camel case in Angular Js

05-03-2017 angularjs camelcase filters