seamlessict / darey

0 stars 0 forks source link

Installing and Setting up ExpressJS and Configuring Routes #15

Closed seamlessict closed 1 year ago

seamlessict commented 1 year ago

Use the NPM package to install express using this command npm install express use the touch command to create a file called index.js (touch index.js) in the root directory and install the dotenv module using the npm package manager npm install dotvenv

Image

type the express configuration setup code into the index.js or open using vim or nano and paste the code from notepad or any other text editor and save it with the esc key : wq shortcut keys

Image

Test the configuration by running the command node index.js. if everything goes well it will show a message Server running on port 5000

Image

go to your EC2 instance created earlier and configure a custom port for 5000 and add a rule for it to be accessed from everywhere.

You can now test that it listening to the port via http (browser) by typing the public -ip-address:5000

Image

Configure the routes for adding (POST request), pulling (GET request) and deleting (DELETE request) this is done by creating a route folder using the mkdir command and crating a file called api.js using the touch command. its in this file that we put the route configuration codes.