10 examples of 'nodejs require local file' in JavaScript

Every line of 'nodejs require local file' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
68function nodeGlobalRequire(file) {
69 process.binding('evals').NodeScript.runInThisContext.call(
70 global, fs.readFileSync(file), file);
71}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

69function nodeGlobalRequire(file) {
70 vm.Script.runInThisContext.call(
71 global, fs.readFileSync(file), file);
72}
97function nodeGlobalRequire(file) {
98 var _module = global.module, _exports = global.exports;
99 global.module = undefined;
100 global.exports = undefined;
101 vm.runInThisContext.call(global, fs.readFileSync(file), file);
102 global.exports = _exports;
103 global.module = _module;
104}
21function evalFileInRemote(file: string) {
22 if (!path.isAbsolute(file)) {
23 file = path.join(UserDataPath, file);
24 }
25 fs.readFile(file, 'utf8', (err, source) => {
26 if (err) {
27 log.error('Error while loading JavaScript source from file ' + file, err);
28 return;
29 }
30 const elem = Store.getState().webview.element;
31 if (!elem) {
32 return;
33 }
34 elem.executeJavaScript(source);
35 });
36}
174require(filename) {
175 let filepath;
176
177 ['', '.js', '.json'].forEach(function(ext) {
178 if (filepath) {
179 return;
180 }
181
182 filepath = this._findSync(filename + ext);
183 }, this);
184
185 if (!filepath) {
186 throw new Error(`Cannot find module '${filename}'`);
187 }
188
189 return require(filepath);
190}
33_requireFile: function _requireFile(file) {
34 return require(file);
35},
502localRequire(name, cwd) {
503 const resolved = this.localResolve(name, cwd)
504 return resolved ? require(resolved) : null
505}
19function custom_require(file) {
20 try {
21 log.info("Requiring: " + file);
22 var rfile = Ti.Filesystem.getFile(file);
23 var contents = rfile.read().text;
24 return eval("(function(exports){var __OXP=exports;var module={'exports':exports};" + contents + ";if(module.exports !== __OXP){return module.exports;}return exports;})({})");
25 } catch(e) {
26 e.file=file;
27 log.error(utils.extractExceptionData(e));
28 }
29}
43export function requireFile (modulePath: string, _default = {}) {
44 try {
45 return require(modulePath);
46 } catch (error) {
47 return _default;
48 }
49}
73public require(filePath: string) {
74 ok(typeof filePath === 'string', 'path must be a string');
75 return Module.loadFile(filePath, this);
76}

Related snippets