In NodeJS, require() is a built-in function to include external modules that exist in separate files. require() statement basically reads a JavaScript file, executes it, and then proceeds to return the export object.
At server side need to render JavaScript code for that you have to install a mock browser package. build your project again with npm run build:ssr and serve with npm run serve:ssr. Hope your all the windows is not define error have been solved now.
The basic functionality of require is that it reads a JavaScript file, executes the file, and then proceeds to return the exports object.
So I am completely new to node but I figured out how to install node_modules. What I am trying to figure out is how to properly include 'Angular' into my code.
So from a new express 4 spin up I did:
npm install --save angular
Then I went into routes/index.js
and added the require('angular')
:
var express = require('express');
var router = express.Router();
require('angular');
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;
But when I do node start I get an error that says:
ReferenceError: window is not defined
at Object.<anonymous> (/Users/al/Projects/node/podcastsearch/podcast/node_modules/angular/angular.js:26307:4)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/al/Projects/node/podcastsearch/podcast/node_modules/angular/index.js:1:63)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
What is the proper way to include angular?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With