stackoverflow back end clone with node.js

Overview

Stackoverflow clone with Node.js

Run

To run this project, download it to your computer and open it with a code editor. Open the .env file in the env folder and firstly give it into MONGO_URL information. MONGO_URL gets database connect link. Like that:

MONGO_URL = mydatabaseconnectlinkexample@mongodb

You should enter other information in the .env file for token and password reset operations. You can find this information at the end of this document under the name "env file". But it's not must for now.

Then you should download the packages that this project depends on from the terminal with the npm install package_name command. Dependencies of this project:

+ bcryptjs: password encryption operations
+ dotenv: configuration of environment variables
+ express: development back end rest api
+ express-async-handler: error handling in async-await codes
+ jsonwebtoken: creating token
+ mongoose: database operations with mongodb
+ multer: uploading profile photo
+ nodemailer: sending mail
+ slugify: creating slug

And you can run now this project with that command:

npm run start

Project Informations

1. stacks:

+ Back end: Node.js, Express.js
+ Database: MongoDB

2. file structure:

+ `server.js`: main file
+ `routes`: a folder that uses the express router feature and keeps the route information in it.
+ `controllers`: a folder that contains controller functions for routes.
+ `models`: a folder that contains user-question-answer models.
+ `middlewares`: a folder that contains middlewares that performs some checks for routes
+ `helpers`: a folder that contains helpers functions like database connection
+ `env`: environment variables
+ `public`: for static files
+ `package.json`: package.json
+ `package-lock.json`: package-lock.json

3. database models:

+ `user`: A user model exists in the database. User can sign up with own email and password. User has the "user" role by default. User can optionally add "title, about, place, website" fields. User can view their own profile and upload profile photo. If user forgot his password, he can reset his password. User can create and answer questions.

+ `question`: A question model exists in the database. User can create questions with the question model. User can edit the questions. User can delete questions. User can add answers to questions.

+ `answer`: A answer model exists in the database.

4. authentication - authorization

This project uses JSON Web Token for authentication and authorization. You will receive a token when you log in. When you want to reach certain routes, middleware decodes this token and if the token is valid, it allows you to switch to the route. If you want to test this project in an API Testing tool, you should send token information in headers in route requests. Like that:

Bearer: {{access_token}}

5. routes

+ `/api/auth/register`: register
+ `/api/auth/login: login
+ `api/auth/:user_id`: fetch profile information
+ `api/auth/logout`: log out
+ `api/auth/forgotpassword`: reset your password
+ `api/auth/resetpassword`: reset your password
+ `api/auth/upload`: upload a profile image
+ `api/auth/userEdit`: edit own informations

+ `api/users/`: get all users
+ `api/users/:id`: get single user with parameter

+ `api/admin`: only for admins
+ `api/admin/block/:id`: block a user as admin
+ `api/admin/delete/:id`: delete a user as admin

+ `api/questions/`: get all questions
+ `api/questions/:id`: get single question by id
+ `api/questions/ask: ask a question
+ `api/questions/:id/like`: like a question
+ `api/questions/:id/undolike`: undolike a question
+ `api/questions/:id/edit`: edit a question
+ `api/questions/:id/delete`: delete a question
+ `api/questions/:question_id/answers`: view answers of a question by parameter

+ `api/questions/:question_id/answers`: add a answer to a question
+ `api/questions/:question_id/answers``: get all answers by question
+ `api/questions/:question_id/answers/:answer_id`: get a single answer by question
+ `api/questions/:question_id/answers/:answer_id/like`: like a answer 
+ `api/questions/:question_id/answers/:answer_id/undolike`: undolike a answer
+ `api/questions/:question_id/answers/:answer_id/edit`: edit a answer
+ `api/questions/:question_id/answers/:answer_id/delete`: delete a answer

6. env file

## Environment Variables

PORT = 5000
NODE_ENV=development

## Database Connect Link

MONGO_URL = // your database connect link

## Json Web Token 

JWT_SECRET_KEY= // your secret key for json-web-token
JWT_EXPIRE= // jwt expire

# Cookie

JWT_COOKIE= // jwt cookie expire

# Reset Password

RESET_PASSWORD_EXPIRE= // reset password expire

# NodeMailer

SMTP_SERVER_HOST=smtp.gmail.com
SMTP_SERVER_PORT=587
SMTP_EMAIL= // your e-mail adress
SMTP_PASS= // your e-mail password

env

You might also like...

Uma aplicação back-end para listar e verificar se o dia é um feriado de acordo com os feriados registrados no sistema

Holydayzer Sobre Uma aplicação back-end para listar e verificar se o dia é um feriado de acordo com os feriados registrados no sistema. Como rodar Exe

Mar 9, 2022

Uma aplicação back-end para consumo e envio de frases/mensagens semelhante ao twitter.

Tweteroo Uma aplicação back-end utilizando o nodemon para rodar o servidor e o express para consumo e envio de frases/mensagens. Rodar projeto Após cl

Feb 3, 2022

A back-end web app allows you to register and login to access a secrets page

A back-end web app allows you to register and login to access a secrets page

Oct 30, 2022

This shows NFT tracking in the certain wallet using express back-end.

nft-tracking-for-solana-wallet Express backend for NFT tracking in the certain wallet. Webhook for scraping secondary marketplace information for part

Nov 16, 2022

E-commerce Back-end Server

Ecommerce Backend Server This project contains the intial setup needed for creating the MVC folder for our Ecommerce-backend application and setting u

Feb 10, 2022

Deploying Fake Back-End Server & DataBase Using JSON-SERVER, GitHub, and Heroku

Deploying Fake Back-End Server & DataBase Using JSON-SERVER, GitHub, and Heroku

Deploying Fake Back-End Server & DataBase Using JSON-SERVER, GitHub, and Heroku. In this article, we will create and host a fake server that we can de

Sep 5, 2022

📜 TypeScript Project Template for Back End Development

TypeScript Project Template Back End Development Project Template Browse TypeScript code» Built With Table of Contents Installation and Usage Error Ha

Dec 31, 2022

Back-end desenvolvido com NodeJS, TypeScript, Prisma e Express para prover dados para as aplicações em desenvolvimento.plicações do evento NLW eSports.

Back-end desenvolvido com NodeJS, TypeScript, Prisma e Express para prover dados para as aplicações em desenvolvimento.plicações do evento NLW eSports.

NLW eSports Back-End Aplicação back-end para surprir as necessidades de dados das demais plataformas desenvolvidas que são citadas mais abaixo. Este s

Sep 17, 2022

Back-End da aplicação EnfUroped V2

Uroped API O EnfUroped API é uma "REST API" que alimenta a aplicação EnfUroped-client, confira vários documentos úteis sobre o projeto na pasta docs.

Oct 9, 2022
Owner
mert
html5, css3, javascript and es6+, react.js, node.js, express.js, mongodb
mert
Pass trust from a front-end Algorand WalletConnect session, to a back-end web service

AlgoAuth Authenticate to a website using only your Algorand wallet Pass trust from a front-end Algorand WalletConnect session, to a back-end web servi

Nullable Labs 16 Dec 15, 2022
It consists of a recreation of Twitter, to put into practice both Front-end and Back-end knowledge by implementing the MERN Stack together with other technologies to add more value to the project.

Twitter-Clone_Back-end ✨ Demo. ?? About the project. ?? Descriptions. It consists of a recreation of Twitter, to put into practice knowledge of both F

Mario Quirós Luna 5 Apr 12, 2022
It consists of a recreation of Twitter, to put into practice knowledge of both Front-end and Back-end implementing the MERN Stack along with other technologies to add more value to the project.

Twitter-Clone_Front-end ✨ Demo. Login Home Profile Message Notifications Deployed in: https://twitter-clone-front-end.vercel.app/ ?? About the project

Mario Quirós Luna 5 Jun 26, 2022
Web-Technology with Aj Zero Coding. In this tutorial we learn front-end and back-end development.

Installation through NPM: The jQWidgets framework is available as NPM package: jQuery, Javascript, Angular, Vue, React, Web Components: https://www

Ajay Dhangar 3 Nov 19, 2022
Import ES Modules from the top StackOverflow answer to a question

StackOverflow Copilot Like GitHub Copilot, but worse! Imports the first codeblock of the first answer to a StackOverflow question as an ES Module Usag

Mary 28 Jan 18, 2022
Fun way to share some of your (already) public StackOverflow user data to the internet.

ProfileOverflow A simple app leveraging StackExchange APIs to show some StackOverflow accounts information. Made for fun during a weekend as practice.

Jacky Efendi 5 Sep 14, 2022
stackoverflow look-alike with only the questions section

q&a forum! Description Made this project in education purpose and to have something to show in my portfolio. I copied parts of stackoverflows design b

William Eliasson 5 Oct 24, 2022
A NPM package powered by Yeoman that generates a scaffolding boilerplate for back-end workflow with Node.js.

generator-noderplate Generate Node.js starter files with just one command! We have deployed a npm package that will generate a boilerplate for nodejs

Samarjeet 3 Jan 24, 2022
RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

Muhammad Ferdian Iqbal 1 Jan 3, 2022
School App / Back-End with MongoDB / mongoose / Express / TS

TEST Api Dependencies El mati se la come es por eso que en 1998 la guerra fria se llevo a mas de la mitad del activo del pais "dependencies": { "axios

Santiago Bancalari 3 Jun 10, 2022