0

First of, I know I can load AngularJS through a script tag but as I have observed it loads faster using NodeJS's require function. But how come when I load it through a script tag, it works. While using require() it doesn't.


Via script tag:

<script src="node_modules/angular/angular.min.js"></script>

Via NodeJS require():

var angular = require('angular');

I can access the "angular" variable either way in the console, but the second one doesn't seem to work as I expect.


EDIT: I have already installed AngularJS using npm. I have also read from their NPM page that it can be used also through require(). But it just doesn't seem to work for me.

3
  • 1
    Please check this link. link Commented Sep 21, 2016 at 4:06
  • Thanks, I have already done that. AngularJS is already in my node_modules, I just cant make it work unlike when loading it via script tag though I can both access them in console. Commented Sep 21, 2016 at 4:11
  • Are you using any framework like expressjs? Commented Sep 21, 2016 at 4:48

1 Answer 1

1

I am not sure why you are trying to load AngularJS library in Node backend part. As you know, AngularJS is frontend Javascript framework, NodeJS is backend Javascript one. So if you use AngularJS, you should choose the first choice that you mentioned.

Or you can install AngularJS on NPM or Bower.

npm install angular
bower install angular

Good Luck!

Sign up to request clarification or add additional context in comments.

2 Comments

Actually I have already installed AngularJS using npm. The reason why I want to do it is because I see that it loads faster.
I think it is necessary for you to install requirejs first before using require command in frontend part. Obviously, I think it is impossible and unnecessary to install angularjs in nodeJS backend part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.