![]() ![]() Now make a ‘server.js’ file in root directory and paste the following code const express = require('express') const server = express() server.get("/", (req, res) => ) module.exports = pool Now lets go ahead and set up express and other important packages, then our local server npm install express cors pg This one small command has now just set upped your node app. Open up the terminal and lets’ begin with command: npm init -y Now create a folder on your PC and open it in VS Code. If you get v14.xx.x something, you are good to go, otherwise you can download node here. You obviously need node installed in your system, you can check it by running node -v Now lets start with node and express and build an API. It means that you are all set to write up your own CRUD API using node and express with PostgreSQL So you just Created, Read, Updated and Deleted data from your database. Update a value in database UPDATE task SET completed = true WHERE work = ‘Learn Postgres’ ĭelete a value from the database DELETE FROM task where work = 'Learn Postgres' Read all the values stored in your database SELECT * FROM task Insert a value in the database INSERT INTO task(work, completed) VALUES('Learn postgres', false) Now you can deal with the data as you are ready to store it now in your relation. You have created a database and a table inside it on your local machine. Switch to the created database \c todo postgres localhost 5432 Ĭreate a relation or a table on created database CREATE TABLE task(work VARCHAR(150), completed BOOL) Īt this point, you are all set. Ok, so make sure you are connected on to your database and lets start,Ĭreate a database on your localhost CREATE DATABASE todo I’m going to assume that you have Postgres installed in your system already, however if that's not the case follow along this video on YouTube and it will get things done for you to follow along. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |