>> What would you recommend I look at in JS land knowing I love django and dislike flask?
I just use typescript and nodejs and the database.
No framework except the express web server.
It's incredibly raw and close to the metal, which I like.
Here's a throwaway example of register and login from ChatGPT to illustrate how easy it is. Totally unchecked but it's just to show approximately what's involved - and it's not much at all.
import express, { Request, Response } from 'express';
import bcrypt from 'bcrypt';
import db from './db';
const router = express.Router();
router.post('/register', async (req: Request, res: Response) => {
const { username, password } = req.body;
// Hash the password
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds);
// Insert user into the database
db.run('INSERT INTO users (username, password) VALUES (?, ?)', [username, hashedPassword], (err) => {
if (err) {
console.error(err.message);
return res.status(500).json({ error: 'Internal Server Error' });
}
return res.status(201).json({ message: 'User registered successfully' });
});
});
router.post('/login', async (req: Request, res: Response) => {
const { username, password } = req.body;
// Check if user exists
db.get('SELECT * FROM users WHERE username = ?', [username], async (err, row) => {
if (err) {
console.error(err.message);
return res.status(500).json({ error: 'Internal Server Error' });
}
if (!row) {
return res.status(401).json({ error: 'Invalid username or password' });
}
const isPasswordValid = await bcrypt.compare(password, row.password);
if (!isPasswordValid) {
return res.status(401).json({ error: 'Invalid username or password' });
}
return res.status(200).json({ message: 'Login successful' });
});
});
export { router as routes };
For database I use the postgres.js library which is super nice
https://github.com/porsager/postgresexamples from postgres.js front page:
import sql from './db.js'
async function getUsersOver(age) {
const users = await sql`
select
name,
age
from users
where age > ${ age }
`
// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]
return users
}
async function insertUser({ name, age }) {
const users = await sql`
insert into users
(name, age)
values
(${ name }, ${ age })
returning name, age
`
// users = Result [{ name: "Murray", age: 68 }]
return users
}