Monday 29 October 2018

Importing an external JavaScript library from a URL in a node.js server

Hey guys, I'm currently developing a REST-API using node.js, which needs two external JS-scripts from a URL for the application logic / algorithm, both in the format of .min.js. Until now I have found 2/3 potential solutions with their own problems:​By using 'http.get' in the script to import them, but it didn't work since it seems the command will import the .min.js in an HTML-format. => Error: , 'SyntaxError: Unexpected token <'By manually saving both .min.js files locally and importing them to the node.js script using imports() function from node-import, but it also didn't work. => Error: 'ReferenceError: window is not defined'Again, saving the files locally, and importing them by using var js1 = require('example.min.js'); and running them by using eval(js1); , which also didn't work, I suppose since they're minified JS. => Error: e is not a constructorIs there anything else I haven't tried, or perhaps is there any workaround to make one of the solutions I've found work?Thanks!EDIT: I'm using LoopBack framework for the REST API.

Submitted October 29, 2018 at 09:54AM by xypherifyion

No comments:

Post a Comment