Learning Chat Functioning With NodeJS, ExpressJS And MongoDB

Here, I use Git, Sublime text editor, NodeJS, MongoDB and ExpressJS. Make sure that you have installed them in your system and if you have not installed them, go to the link, download and install them all. Installation is not hard but make sure that you follow all the given instructions.

After completing all the procesess, your project may look like this:

project

project

So let’s start

On a desktop, create a new folder and name that chat app. Right click on the folder and open it on your gitbash and hit enter. After, write on your git bash npm init and follow the instructions shown below:

instruction

After completing the process, you open this folder on Sublime text and check that you have packeg.json, as shown below:

json

You create app.js file on your folder.

Now, you add some useful middleware on your package.json,as shown below:

  1. MongoDB (npm install mongo dB –save)
  2. Socket.io (npm install socket.io –save)

    add

Make sure that your package.json looks as shown below:

json

After creating, you will add middleware on app.js & create connection with MongoDB.

connection

After creating connection, make sure that you have one index file for views and if is not there then just add that on your folder and write that code.

code

Add all your code, make sure that your Server is running and if it is not working, just type command node app.js and hit enter on your Server, which is running now. After running the Server, go to your folder, open your folder and open your index.js, which is opened in the Browser that you have.

It’s only for demo purposes and you can make it better by trying it yourself.


Similar Articles