- nodemon to watch for changes and restart the server
- Babel to enable JavaScript feature not enabled in Node.js
- Dotenv to load environment variables from a .env file
- Express for backend
- Middleware
- CORS to enable cross-origin requests
- Custom middleware for routes
PORT=3000 # Port to run the server on
DATABASE='PostgreSQL-DB-Name' # Name of the database to use
DATABASE_USER='db_username' # Username to connect to the database with
DATABASE_PASSWORD='db_user_password' # Password to connect to the database with
ERASE_DB_ON_SYNC=true # If true, erases the database on sync. It will not if false.
USERS_AMOUNT=100 # Amount of users to generate
- User
- username
- name
- phone
- birthday
- password
- Message
- text
- user_id
Each time the server starts, the database is regenerated. To change the database configuration, you can set the following environment variables:
ERASE_DB_ON_SYNC=false
To change how many users with random messages are generated, set the following environment variable to set the number of users to generate:
USERS_AMOUNT=10
The server defaults to a random number of users between 1 and 100. The first generated user is hard coded to the following:
{
"id": 1,
"username": "admin",
"email": "admin@localhost.com",
"name": "Adrian Mroz",
"phone": "+1(443)216-9316",
"birthday": "1988-05-18T00:00:00.000Z",
"password": "password",
}
And that is all you need to do to change the database configuration.
curl -X GET http://localhost:3000/users
curl -X GET http://localhost:3000/users/1
curl -X GET http://localhost:3000/messages
curl -X GET http://localhost:3000/messages/1
curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d
`{
"username": "newuser",
"email": "PostUser@postman.com",
"name": "Post User",
"phone": "+1(800)123-1234",
"birthday": "1950-01-20T00:00:00.000Z",
"password": "dVmMyp@55word"
}`
curl -X POST http://localhost:3000/messages -H "Content-Type: application/json" -d
`{
"text": "This is a message",
}`
curl -X PUT http://localhost:3000/users/2 -H "Content-Type: application/json" -d
`{
"username": "newuser",
"email": "newEmail@github.com"
}`
curl -X PUT http://localhost:3000/messages/2 -H "Content-Type: application/json" -d
`{
"text": "This is a new message",
}`
curl -X DELETE http://localhost:3000/users/2
curl -X DELETE http://localhost:3000/messages/2