Skip to content

Instantly share code, notes, and snippets.

@alperbayram
Created February 7, 2022 12:24
Show Gist options
  • Save alperbayram/dfb5ba7f688e8ef18c902c436cf57dc8 to your computer and use it in GitHub Desktop.
Save alperbayram/dfb5ba7f688e8ef18c902c436cf57dc8 to your computer and use it in GitHub Desktop.
app
const express = require('express');
const path = require('path');
const dotenv = require('dotenv');
const ContactRoute = require('./Routes/ContactRoute');
const app = express();
dotenv.config();
//middleware
app.use(express.static(path.resolve(__dirname, '../client/build')));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//routes
app.use('/', ContactRoute);
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '../client/build', 'index.html'));
});
//connect port
const port = process.env.PORT || 3001;
app.listen(port, () => {
console.log(`Server listening on ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment