Friday, 5 May 2017

node app.js results in "window not defined"

From research in this Stack Overflow post, I understand that this has to do with window being defined in the browser and not in node. However, I'm not entirely clear on how to remedy the situation. My goal is to just start my server so I can preview a website I built (and make sure it looks good).

Here's my app.js file:

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(80);

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

io.on('connection', function (socket) {
  socket.emit('answers', { hello: 'world' });
  socket.on('gum', function (data) {
    console.log(data);
});
});

angular.module('NoteWrangler', ['ngRoute', 'ngResource']);

Here's the error I get when entering node app.js into Terminal:

/Users/Kristin/node_modules/angular/angular.js:26057
})(window, document);
   ^

ReferenceError: window is not defined
at Object.<anonymous 
(/Users/Kristin/node_modules/angular/angular.js:26057:4)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/Kristin/node_modules/angular/index.js:1:63)
at Module._compile (module.js:570:32)



via Koberlander

No comments:

Post a Comment