This is a simple server template to for my students to start projects quickly.
- Setup
- Endpoints
- Sample requests with axios
- Sample requests with httpie
- History of this project (pullrequests)
- Create a new project based on this template using the
Use this template
button
- Clone the app
git clone git@github.com:YOUR_GITHUB_NAME/YOUR_PROJECT_NAME.git
- cd into your project
cd YOUR_PROJECT_NAME
- install dependencies
npm install
- 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
- 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
- start server with
nodemon
(recommended for development)
npm run dev
- or start normally
npm start
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 |
To demo making request to this server, some small script are included that make requests using axios
The scripts can be found in /sampleRequests
- Make sure to follow the the setup in this readme first
- cd sampleRequests
- Run example requests
node hello.js
node echo.js
node signup.js
node login.js
node me.js
node authorizedPost.js
To demo making request to this server, bash commands are included that make requests using httpie
They can found in ./sampleRequests/httpie.md