2

I am trying to merge a working Socket.io, AngularJS and ExpressJS 3.x project into the new Yeoman: Express Stack.

I started by following the directions given on https://github.com/yeoman/yeoman/tree/express-stack, namely,

yeomen init angularcrud # Standard Angular app

yeomen init angularcrud:crud post # Angular CRUD routes/views

yeomen init express post # Express CRUD

yeomen server

I have merged the codes carefuly checking that at each point the new code works. This process is sucessful until I add socket.io. At that point, when I run "yeoman server", I get the error "/socket.io/socket.io.js Not Found" which is substantially similar to the error in the following question Socket.io not being served by Node.js server. In First Zero's answer to the question, he states that "node_modules should be in the same directory as server.js, not above server root". In the directory set-up that Yeoman: Express Stack creates, this is exactly the situation, node_modules is one level above the server root (index.js). If one simply moves index.js to the same level as node_modules, one gets a cannot find module error.

I would like to know how to modify the set-up to get Yeoman: Express working with socket-io.

Community
  • 1
  • 1
C R
  • 2,182
  • 5
  • 32
  • 41

2 Answers2

0

I've been testing this branch a bit the last few days though not with socket.io class I know this much that node_modules goes in the project root not in server/

You may need to either install socket.io via npm as a global or put ../ before before your require('../socket.io') or something. Also we do what most Express/Angular stubs/seeds/examples have too which is to include a wildcard route at the end of Express route definitions.

If you also need a catchall route and/or set html5mode to true then you need to make sure you define it like below or angular spirals your client session into a self-referencing loading loop:

app.get(/^((?!\/styles|scripts\/).)*$/, function(req, res){
  res.render('<app_path>/app/index.html'); // or chrome.html if you call it such

});

Hope that helps somewhat

Vodbro
  • 1
0

Another idea for your module issue try going into /yeoman-custom dir and installing it there as that is the actual root that yeoman-custom/cli/tasks/server.js serves up with Node.

Vodbro
  • 1