Skip to content

Commit

Permalink
all setup configured
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshchoudhary committed Nov 19, 2023
1 parent 5f45529 commit acdad8d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ app.use(express.static("public"))
app.use(cookieParser())


//routes import
import userRouter from './routes/user.routes.js'


//routes declaration
app.use("/api/v1/users", userRouter)

// http://localhost:8000/api/v1/users/register

export { app }
13 changes: 13 additions & 0 deletions src/controllers/user.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { asyncHandler } from "../utils/asyncHandler.js";


const registerUser = asyncHandler( async (req, res) => {
res.status(500).json({
message: "chai aur code"
})
} )


export {
registerUser,
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// require('dotenv').config({path: './env'})
import dotenv from "dotenv"
import connectDB from "./db/index.js";

import {app} from './app.js'
dotenv.config({
path: './env'
})
Expand All @@ -11,7 +11,7 @@ dotenv.config({
connectDB()
.then(() => {
app.listen(process.env.PORT || 8000, () => {
console.log(`⚙️ Server is running at port : ${process.env.PORT}`);
console.log(`⚙️ Server is running at port : ${process.env.PORT}`);
})
})
.catch((err) => {
Expand Down
9 changes: 9 additions & 0 deletions src/routes/user.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Router } from "express";
import { registerUser } from "../controllers/user.controller.js";

const router = Router()

router.route("/register").post(registerUser)


export default router
2 changes: 1 addition & 1 deletion src/utils/ApiError.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ApiError extends Error {
statusCode,
message= "Something went wrong",
errors = [],
statck = ""
stack = ""
){
super(message)
this.statusCode = statusCode
Expand Down
4 changes: 2 additions & 2 deletions src/utils/asyncHandler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const asyncHandler = (requestHandler) => {
(req, res, next) => {
return (req, res, next) => {
Promise.resolve(requestHandler(req, res, next)).catch((err) => next(err))
}
}


export {asyncHandler}
export { asyncHandler }



Expand Down

0 comments on commit acdad8d

Please sign in to comment.