Q:

Express JS and SocketIO Using

Sorry guys, I am here to ask about how to using the express js and socket io. I am really new to this kind of tech.
The
1st question is, is it really necessary to install express for every project? I mean, when I want to create a new project,I create a new folder, should I run a new command prompt, point to the directory and install express? If so, tell me to do it offline please? Because sometimes I cant connect to the Internet.
The 2nd question is, if I use express JS, shall I place the client file such as html / javascript(front end) in the same directory with the server file? How can I run an example express project from external source, such as github?
3rd question is, I have seen a lot tutorial about express JS + SocketIO. Those two things are framework,right? How can I use them together in a project / a folder?
Really appreciate and big thanks if you guys help, thank you :)

A:

Question 01:
Answer: You don't have to install Express on each of your project in order to use it. You can simply run this command and it will install it globally and you can have it offline.
npm install -g express

The above command will install express globally, so now you can use it offline as well.
Question 02:
Answer: The recommendation of placing any static files (HTML/JS/CSS/IMG) to a different folder than any of your server-side files because you don't want to expose any of your server-side files to the public.
This structure should be something you follow:
├───server.js
├───lib.js
├───views
│   └───*
├───public
│   ├───js
│   │   └───*
│   ├───css
│   │    └───*
│   ├───img
│        └───*

So as you can see above the views.js would be any of your rendering files that will be use with the templating system such as index.html, layout.html
Question 03: 
Answer: In express you can use app.use to integrate any middleware or framework to make it work together. I recommend you to read their API on how it works.
Hope this help.

