반응형
[NodeJS] Realtime Chat with Node.js
http://tutorialzine.com/2014/03/nodejs-private-webchat/
In this tutorial, we are going to build a realtime chat system with Node.js and the socket.io library. The chat permits users to create private chat rooms that they can share with a friend. For avatars, we will use gravatar. You can run the chat locally with node, or push it to heroku or a different cloud service provider.
The code
You can grab the source code from the download button above. It has plenty of comments and is easy to follow. Start with the app.js file and read from there. Here are a few things to look for:
- All dependencies are declared in the package.json file. They are not included in the zip and you will have to run
npm install
to get them. - We are using separate JavaScript files for the configuration and routes, to make the code more manageable.
- In the routes file, socket.io stores the username, avatar and room of the person as properties of the socket object itself. This saves us a lot of code and makes managing rooms easy.
- We use socket.io‘s rooms feature to isolate one chat from another, which is exactly what that feature was developed for.
반응형
'프로그래밍 > Script' 카테고리의 다른 글
[javascript] 15 Interesting JavaScript and CSS Libraries for February 2017 (0) | 2017.03.22 |
---|---|
[javascript] 10 Tips for Writing JavaScript without jQuery (0) | 2017.03.22 |
if(window.console!=undefined) console.log.bind() (0) | 2017.03.14 |
[Node.js] Node.js, Express, MongoDB를 이용하여 REST API 만들기 (0) | 2017.03.08 |
[jQuery] jQuery로 모바일에서 가로보기인지 세로보기인지 알아내기 (0) | 2016.12.29 |