So, I did now open up Cursor here in a brand new folder, an empty folder, where I want
to put all that code for my REST API.
Now I got one example folder structure suggested here and I'll at least implement parts of
that.
I will need a package.json file to manage my dependencies.
I want to have a root entry file, though I will name mine app.js.
I will add such a .env file to store, for example, my JSON Web Tokens secret.
And I will add some of these folders, though not in a source subfolder, but instead directly
in the root directory.
And I also won't add all of them.
So to get started, I'll first run npm init dash y to create this package.json file.
And I could ask AI for that, of course.
I could use that inline chat here to, say, generate a new package.json file.
And it likely would suggest the same command.
Yes, it does.
But of course, that is already a first example for something where I could use AI, but it
actually takes me more time because I already know the command.
Nonetheless, now that I showed you how you could use AI, I'll just use this command
and click run here to run it.
And this generates this package.json file.
Now here in that file, I already want to change some things.
And again, I'll do that manually because I know exactly what I want to change.
I'll put in my name here and the name of my company.
I will change the main file to app.js because that's the name I'll choose.
I'll add type module, getting a nice suggestion here, which I'll just confirm by hitting
tab, which allows me to use a different import and export format in this application.
And I also will change that script.
I'm getting some suggestions here, but hard to see.
Let me zoom out.
Yeah, these are not exactly the scripts I want.
Instead, I will add a dev script, but I will accept the suggestion here, but I will not
run app.js with an extra tool called nodemon.
Instead, since I'm using a fairly recent version of node.js, I'll use the built-in
watch mode, which is now suggested to me to run my application in watch mode where the
server will be restarted whenever I make changes.
Now we could add more scripts, but that's the basic behavior I want and need here.
Okay, so that's the package jsonfile edited.
As mentioned, I'll add a .env file to hold some environment variables, which I'll need
later.
And I'll actually also add a gitignore file, even though it was not suggested because I
plan on using git here for this project.
And that's why I add this file.
And here I want to ignore this special file here, which is a Mac-specific file, the .env
file for sure, and node modules.
So I'll accept these suggestions here, whoops, like this, and that's my gitignore file.
Well, and now I'll add an app.js file, which will be my root entry file for this application.
I also need to install dependencies, one dependency to get started, and that will be the express.js
package, which I can install with this command here, because I'll use the express framework
to build this node.js REST API.
But again, you don't need to know express or node.
You can just copy my code, follow along, and you'll be fine.
Now if you don't know node.js, though, it's worth noting that you need to visit nodejs.org
and download node.js from there.
It's available for all operating systems.
And install it on your system so that you will be able to run this application.
Obviously this npm init command from before will already fail if you don't have node.js
installed, so you will need that.
And with that, I got the most important files set up here.
Now I will also add a couple of folders, though, a couple of folders which I'll need, some
of which have been suggested here by chat.gpt.
For example, I will add a controllers, a models, and a routes folder.
So I'll do that here, not inside of a src folder, though, but instead here in the root
project folder, controllers, models, and routes.
And I'll also, in addition, add a public folder which will, for example, later hold my uploaded
images in an images subfolder.
So these are some folders I want to create, even though they hold no files yet.
Because that's what I'll now try to do in a next step with more help by cursor.
Because up to this point I did basically all of that manually because I knew exactly what
I needed.
Now I'll try to generate some code and files with help of cursor.