This is a very basic node server which has authentication with jwt tokents and mongodb for database.
NodeJS v10 or greater npm v6 or greater
git clone https://github.com/ceyhuncicek/jwt-express-react-example
cd jwt-express-react-example
npm install
You can install mongo db locally or you can use mongo db atlas.
- Create a .env file on the root.
- Go to https://docs.mongodb.com/manual/installation/ follow guides install mongodb on your computer start it and provide the link in .env file or provide a link from mongo atlas.
- Your .env file should look something like below.
DB_CONNECT = mongodb://127.0.0.1:27017/users_db
TOKEN_SECRET = veryverysecretsomerandomlettersandnumbers
PORT = 5000
- That's all! Now Start the project.
npm run start
or
yarn start
Test requestes provided in TestRequests.http
file. You can use Rest Client extension for VsCode. Just uncomment correct block and it will ask you to make request.
Or you can use tools like postman, postwoman, insomnia etc.
Make POST request to localhost:5000/api/user/register
with name
email
and password
to register an user account.
Make GET request to localhost:5000/api/user/login
with email
and password
to login an user account.
When you login you will get a jwt token. You can use this token in your header in your further requests. Jwt token will be recognized and you will be able to do other requests without login.
- mongoose - Database
- express - Web framework
- jsonwebtoken - Tokens
- bcryptjs - Crypt passwords
- joi - for form validation