Coder Social home page Coder Social logo

cool-story-backend's Introduction

Server template

This is a simple server template to for my students to start projects quickly.

Table of contents:

SETUP How to use this template

  1. Create a new project based on this template using the Use this template button

HOW_TO_USE

  1. Clone the app
git clone [email protected]:YOUR_GITHUB_NAME/YOUR_PROJECT_NAME.git
  1. cd into your project
cd YOUR_PROJECT_NAME
  1. install dependencies
npm install
  1. Configure your database in config/config.json

Default config is setup for usage with an ElephantSQL database instance, you need to provide the DB Url on the "url" key of the config.json file, key development.

// config/config.json
{
  "development": {
    "url": "YOUR_ELEPHANTSQL_URL_HERE",
    "dialect": "postgres",
    "operatorsAliases": "0"
  },
}

If planning to use this template with a docker database the config object should be changed to:

// config/config.json
{
  "development": {
    "username": "postgres",
    "password": "secret",
    "database": "YOUR_PROJECT_NAME_HERE_development",
    "host": "localhost",
    "dialect": "postgres",
    "operatorsAliases": "0"
  }
}

And you must revert the changes on this line in models/index.js: https://github.com/Codaisseur/express-template/commit/ada7711c8b19c8f240bc61f94743213efe4a77d2#diff-18c449caa39363f82bacb4f7489e7783L15

  1. Create database, run migrations & seed data

package.json contains a script for this

npm run initdev

Or run the commands seperately

npx sequelize-cli db:migrate
npx sequelize-cli db:seed:all
  1. start server with nodemon (recommended for development)
npm run dev
  1. or start normally
npm start

Endpoints

Method Path Purpose required parameters auth
GET '/' Test if your server is running none no
POST '/echo' Test POST requests none no
POST '/signup' Create a new user and get a token email, name, password no
POST '/login' Get a token with email & password email, password no
GET '/me' Get information of this user none yes
POST '/authorized_post_request' Test POST requests (token required) none yes

Sample requests with axios

To demo making request to this server, some small script are included that make requests using axios

The scripts can be found in /sampleRequests

  1. Make sure to follow the the setup in this readme first
  2. cd sampleRequests
  3. Run example requests
node hello.js
node echo.js
node signup.js
node login.js
node me.js
node authorizedPost.js

Sample requests with httpie

To demo making request to this server, bash commands are included that make requests using httpie

They can found in ./sampleRequests/httpie.md

History of this project

cool-story-backend's People

Contributors

swetaraj4194 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.