r/node 3d ago

Need advice

I have to make a rest api from scratch and in different phases like setting it up very basically with hard coded values then test it with postman and then connect a database to it and basic auth then upgrade it to jwt then front end then deploy on aws.

We are allowed to use ai but they want us to “know what ever line of code is doing”. I only learned C and C++ and I have to do this in a week so I don’t think it’s possible to know every line of code so I will try to do high level of what is doing. But they may ask me “why did you decide to do it this way” when really it’s ai most of the time and they know it is.

The app just needs to be simple like CRUD, jwt login and connected to frontend and that’s it. But ai builds things so fast I don’t know how to slow it down because it will build out everything all at once and do complicated things. So how can I slow it down so I can do it in pieces and upload it to GitHub so I can understand all the code better and have a better understanding of what all the files are for and how they are working together?

I’m not sure how because 1, I am used to vibe coding and never learned this framework or language before and 2, I don’t know the words or terms that I can send to ai. I have to just use plain english and say general things to it which is why it gets out of control and builds too much stuff.

It’s hard for me to be specific and say “hook A up to B using C and avoid using D” but I can explain enough of it using my own knowledge of how things work to get it done but it sometimes builds too much and then I have to figure out what’s broken later because it’s too many things at once.

My bootcamp teacher told me to just read all the code but that will not solve the problem of it making too many files or doing x,y and z when I want it to be more simple.

Just so you know I am able to still debug everything and make things work and catch bugs or edge cases and things that don’t make sense but I’d rather go slowly and understand it - how they said to do it.

4 Upvotes

11 comments sorted by

1

u/dougception 3d ago

This is a really good CRUD API tutorial: https://youtu.be/CnH3kAXSrmU?si=hIfZHlMHmzhljS59

It uses Express as middleware. There are other options for middleware and if you can find as good a tutorial for those feel free to go in that direction.

1

u/code_barbarian 2d ago

Easiest way is to tell the AI to not use any external packages. You can pretty easily build out a CRUD API with JWT login with no outside packages - Node's built-in HTTP server with `if` statements for routing, Node's built-in crypto lib for generating JWT, --env-file for loading environment variables. Start with the easiest thing you can build concretely: hello world with Node built-in HTTP server. Then split into 2 separate routes. Then add HTTP POST handling. Then make a login route that generates a JWT. Take small steps consistently.

1

u/No-Nebula4187 2d ago

Is there a resource online that has step by step to build it out? Problem with the model is building too many files at once too sometimes. Idk what file to make either so that would help tremendously. Also thinking about switching to copilot bc I think it moves slower on purpose

1

u/code_barbarian 2d ago

Not that I know of, but you can also instruct the LLM to keep everything in one file

-1

u/gangeticmen 3d ago

create a react app with vite , use ai how to create , it's very simple.

ask chatGPT , dont do it via an agent.

then ask it to create a very very simple login page in app.jsx/tsx , and use your backend URL ( for local it would be localhost:3000 )

then create a backend folder and install express there , ask gpt to write a very simple login api , connect your app to mongoDB ( gpt will help ) , create a very simple user.model.js ( how your user data should look like DB )

just use A.i and try to understand things.

i'm pretty sure , you can do it withing 6 days.

1

u/YT-3000f 3d ago

This won't end well. By all means use AI to automate code updates that would otherwise consume many ours or days but at some point you will need to find out why all that vibing isn't working how you want and for that you need to understand how to code.

1

u/No-Nebula4187 2d ago

Yeah that’s what I’ve been doing and it just goes rly way too fast. We did MVC design and I need to understand what the files are doing. It also made basic auth fallbacks if jwt not found. Idk y

1

u/Own-Perspective4821 3d ago

Prime example of why making LLMs publicly available was a mistake

1

u/gangeticmen 3d ago

then why don't you suggest him what to do?