https://replit.com/@AanandaGiri/vertexhacks#server.js https://vertexhacks.aanandagiri.repl.co/
https://github.com/team-hustler/backend
connectionString in connection.js is address given by: ngrok tcp 5432
- GET https://vertexhacks.aanandagiri.repl.co
- (localhost) GET http://localhost:3000
- list of registered users
- Example: open url in browser
- POST https://vertexhacks.aanandagiri.repl.co
- (localhost) POST http://localhost:3000
- params: (username, age, email, phonestr:10, location, contributions, date, duration)
- To add new user
- Example:
// <nodejs code> : create new uesr
const axios = require('axios');
const data = {
username: 'ritik',
age: 116,
email: 'neumon@neumon.neumon',
phone: '0100000000',
location: 'DC',
contributions: 'computer, economics, physics',
date: '2023/02/16',
duration: '48 hours'
};
console.log(data);
axios.post('https://vertexhacks.aanandagiri.repl.co/', data).then(response => {
console.log(response.data);
}) .catch(error => {
console.log(error);
});
# <python code> Test create new uesr
import requests
data = {'username': 'ritik', 'age': 116, 'email': 'neumon@neumon.neumon', 'phone': '0100000000', 'location': 'DC', 'contributions': 'computer, economics, physics', 'date': '2023/02/16', 'duration': '48 hours'}
print(data)
requests.post('https://vertexhacks.aanandagiri.repl.co/', data).text
- POST https://vertexhacks.aanandagiri.repl.co/sms
- (localhost) POST http://localhost:3000/sms
- params: (messsage, to)
- to send sms
- Example:
# <nodejs code> : /truncate endpoint
const axios = require('axios');
const data = {to:'phone_number', message:'should work'}
axios.post('https://vertexhacks.aanandagiri.repl.co/sms', data).then(response => {
console.log(response.data);
}) .catch(error => {
console.log(error);
});
import requests
data = {'to':'phone_number', 'message':'hi'}
requests.post('https://vertexhacks.aanandagiri.repl.co/sms', data).text
- POST https://vertexhacks.aanandagiri.repl.co/truncate
- (localhost) POST http://localhost:3000/truncate
- To truncate the database
import requests
requests.post('https://vertexhacks.aanandagiri.repl.co/truncate', {}).text
- File Coin
npm init node -v & npm -v # node and npm version npm install passport-local #login npm install pg # Connect to postgresql npm install express # for webserver npm install cors # API permissions npm install dotenv
nodemon server.js
-
postgresql with node https://github.com/oliverjam/learn-node-postgres
-
nodemon and express https://medium.com/analytics-vidhya/very-simple-rest-api-using-express-js-5e4ebfad0af2
sudo su - postgres psql
CREATE USER vertex SUPERUSER PASSWORD 'vertex'; CREATE DATABASE vertex_db WITH OWNER vertex; \connect vertex_db
BEGIN;
DROP TABLE IF EXISTS volunteers CASCADE;
CREATE TABLE volunteers ( id SERIAL PRIMARY KEY, username VARCHAR(255) NOT NULL, age INTEGER, email VARCHAR(255), phone VARCHAR(10), location VARCHAR(255), contributions VARCHAR(255), date VARCHAR(10), duration VARCHAR(10) );
COMMIT;
INSERT INTO volunteers (username, age, email, phone, location, contributions, date, duration) VALUES ('neumon', 116, 'neumon@neumon.neumon', '0100000000','DC', 'computer, economics, physics', '2023/02/16', '48 hours');
select * from volunteers;
psql volunteer
\include workshop/database/init.sql
\dt
ngrok tcp 5432
psql -U postgres -h localhost -p 5432 postgres
ngrok tcp 5432
psql -h 0.tcp.ngrok.io -p 17618 -U postgres -d postgres