Skip to content

Instantly share code, notes, and snippets.

@edoves
Created November 14, 2023 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edoves/e69651da75d3c7d73fc47bb41d92883d to your computer and use it in GitHub Desktop.
Save edoves/e69651da75d3c7d73fc47bb41d92883d to your computer and use it in GitHub Desktop.
settiing up nodejs server
const express = require('express')
const cors = require('cors')
const cookieParser = require('cookie-parser')
const app = express()
const postRoute = require('./routes/post.route.js')
const userRoute = require('./routes/user.route.js')
const corsOptions = {
origin: true,
credentials: true,
}
// middleware
app.use(cors(corsOptions))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser())
// routes
app.use('/api', userRoute)
app.use('/api', postRoute)
module.exports = app
const http = require('http')
const app = require('./app.js')
const server = http.createServer(app)
const PORT = process.env.PORT || 5000
server.listen(PORT, () => console.log('Listing to port ' + PORT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment