You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use your existing backend code with your migrations/seeds
touch index.js to create your main server file
npm install express
npm start script
Set up your server file and db file
//index.jsconstexpress=require("express")constapp=express()constPORT=process.env.PORT||8000app.get("/robots",(req,res)=>{res.send("here are the robots")})app.listen(PORT,function(){console.log("Server started on port: ",PORT);})
//robotModel.jsconstpool=require("../db")classRobotModel{staticasyncgetAllRobotsFromDB(){constquery=awaitpool.query("SELECT * FROM robots;")returnquery.rows}}module.exports=RobotModel
//userModel.jsconstpool=require("../db")classUserModel{staticasyncgetSingleUserFromDB(id){letquery=awaitpool.query("SELECT * FROM users WHERE id = $1",[id])returnquery.rows}staticasyncgetUsersRobotsFromDB(id){letquery=awaitpool.query("SELECT * FROM user_robots JOIN robots ON user_robots.robot_id = robots.id WHERE user_id = $1",[id])returnquery.rows}}module.exports=UserModel