0

My title for my first time

#### Install required packages: ```bash npm install express mongoose bcrypt jsonwebtoken ``` #### Create the server: ```javascript // server.js const express = require('express'); const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken'); const app = express(); app.use(express.json()); mongoose.connect('mongodb://localhost:27017/tempService', { useNewUrlParser: true, useUnifiedTopology: true, }); // User Schema const userSchema = new mongoose.Schema({ username: String, password: String, role: String, // 'employer' or 'employee' }); const User = mongoose.model('User', userSchema); // Register app.post('/register', async (req, res) => { const { username, password, role } = req.body; const hashedPassword = await bcrypt.hash(password, 10); const user = new User({ username, password: hashedPassword, role }); await user.save(); res.status(201).send('User registered'); }); // Login app.post('/login', async (req, res) => { const { userna

3rd Oct 2024, 10:24 AM
Bamaboi Rivers
Bamaboi Rivers - avatar
2 Answers
+ 3
Bamaboi Rivers , not clear what your intention for this code is. > since this is the `q&a` forum, please form a question with all required information. > if you are just going to present your code: this is nof the right place to post it.
3rd Oct 2024, 11:47 AM
Lothar
Lothar - avatar
0
Maybe we can create a group on whatsapp invite friends share the idea of coding together and help solve coding problems that will be a lot easier
4th Oct 2024, 3:18 PM
Jonathan Asante