• Stars
    star
    151
  • Rank 238,210 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Realtime Anonymous Chat application with NodeJS, Express, Mongodb and SocketIO

Anonymous Real-time Chat

Introduction

This is anonymous chat app was created for a tutorial about Nodejs, Express, and Socket.io and MongoDB.

You should have a good understanding of how socket.io works at the end of this tutorial or after taking a look at the code.

You will also learn how to show that someone is typing in a chat application.

Here is a screenshot of it looks and functionality.

alt text

Code Samples

Backend

//integrating socketio
socket = io(http);

//database connection
const Chat = require("./models/Chat");
const connect = require("./dbconnect");

//setup event listener
socket.on("connection", socket => {
 console.log("user connected");

 socket.on("disconnect", function() {
   console.log("user disconnected");
 });

 //Someone is typing
 socket.on("typing", data => {
   socket.broadcast.emit("notifyTyping", {
     user: data.user,
     message: data.message
   });
 });

Frontend

(function() {
  $("form").submit(function(e) {
    let li = document.createElement("li");
    e.preventDefault(); // prevents page reloading
    socket.emit("chat message", $("#message").val());

    messages.appendChild(li).append($("#message").val());
    let span = document.createElement("span");
    messages.appendChild(span).append("by " + "Anonymous" + ": " + "just now");

    $("#message").val("");

    return false;
  });

  socket.on("received", data => {
    let li = document.createElement("li");
    let span = document.createElement("span");
    var messages = document.getElementById("messages");
    messages.appendChild(li).append(data.message);
    messages.appendChild(span).append("by " + "anonymous" + ": " + "just now");
    console.log("Hello bingo!");
  });
})();

Installation

Clone this repository and run

npm install

Then run:

npm start

goto your browser

and visit localhost:5000 and start chatting.

Note:

You should have mongoDB installed and started for this application to work correctly.

More Repositories

1

forgotpassword

A secure way to implement forgot password
JavaScript
72
star
2

sendbitcoin

A simple sample code to allow you send bitcoin with Javascript
JavaScript
9
star
3

theatrejs

TypeScript
4
star
4

express-starter

Express Starter App
JavaScript
4
star
5

rust-web

A simple Web app with Rust, Diesel, and PostgreSQL
Rust
4
star
6

pwa-generator

Command-line tool for initializing Progressive Web Apps (PWAs) using Rust
Rust
3
star
7

node-env-sample

JavaScript
3
star
8

crypto-to-localcurrency-converter

Basic node module to allow you convert crypto prices to your local currency
JavaScript
3
star
9

html-email-template

An responsive email template you can use for your welcome email notifications or anything.
HTML
3
star
10

simple-dev-profile

SImple Developer profile
SCSS
3
star
11

hek

A basic standard Ecommerce API build with expressjs
JavaScript
3
star
12

savings-smart-contract

Solidity
3
star
13

paye-tax

Ngpayetax is a very simple Pay As You Earn module. It allows you to easily calculated your employee's tax according to the recent tax table.
Python
3
star
14

job-board

VueJs Job board: A simple implementation of vue and vuex to create a job board
HTML
3
star
15

basic-nextjs-app

JavaScript
2
star
16

rust-challenges

Tiny Challenges to help you get familiar with Rust
Rust
2
star
17

laravel-react-stream-livechat

PHP
2
star
18

rust-web-starter

Rust Web Starter App
Rust
2
star
19

encrypt-decrypt

A simple Rust code to encrypt and decrypt a text with Advance Encryption Standard
Rust
2
star
20

htmlcalculator

This is just a simple HTML calculator newbies can use to learn from. its absolutely simple.
HTML
2
star
21

near-shipment

A basic shipment smart contract. Allows you to add shipments and track the delivery of your shipment
Shell
2
star
22

ada

ada compliance plugin
CSS
2
star
23

standardERC20-token

Solidity
1
star
24

Django-Query-Set-Values

Django Query Set values and Use cases
1
star
25

eth-price-prediction-bet

Solidity
1
star
26

aws-auth0

JavaScript
1
star
27

music-downloader-tag-inserter

PHP
1
star
28

aws-serverless-auth0-react-amplify

JavaScript
1
star
29

ProgressBar

A simple Progress Bar Easy to use better customized than the winform progressbar
C#
1
star
30

vanilajs-chat-app-stream

Basic Implementation of Stream Chat with VanilaJS
JavaScript
1
star
31

adonis-todo

SImple Todo App With AdonisJS and SQLite3
JavaScript
1
star
32

decentralizedvoting-solidity

Solidity
1
star
33

qrcode-with-django

This is a very simple and basic implementation of creating and reading a QRcode with python and Django
Python
1
star
34

todo-rust

Rust
1
star
35

simple-shipment-flask

Flask Tutorial
Python
1
star
36

ccross

JavaScript
1
star
37

subscription

Python
1
star
38

deck-of-gifts

JavaScript
1
star
39

write-web

HTML
1
star
40

QRcode-Generator-and-Decoder

This is a very simple and basic implementation of creating and reading a QRcode with python
Python
1
star
41

django2-Basic-Blog

You can use this to bootstrap your blog development or to study and understand how django 2.0 works.
JavaScript
1
star
42

aisaturday

Jupyter Notebook
1
star
43

formatTimeStamp

Easily convert time stamps to user readable date and time
JavaScript
1
star
44

javascript-reactjs-chat-app

ReactJS Chat App (Includes 100% Ready UI)
JavaScript
1
star