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:

Simple Array Sum | Javascript | hackerrank.com

07-05-2020 hackerrank.com javascript arrays array sum

How To Get Your Blogs Posts Using Blogger API

30-07-2017 blogger api json php

Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js

05-03-2017 mm-dd-yyyy HH:MM date formats angular js

How to set or update or push the values into Object in javacript

27-02-2017 javascript set update push object

Email validation regular expression in javascript

22-02-2017 email validation regex