DEV Community

swapnil ahmed shishir
swapnil ahmed shishir

Posted on

2

Node Server Setup

1 . give new folder name ServerSide or backendServer

  1. write this text $ npm init -y
  2. create file Server.js
  3. install this npm service $ npm install express mysql cors cookie-parser bcrypt jsonwebtoken multer path nodemon 5.create 5 impotent folder in MVC Public/images , Routers , Models , controllers , Utils ,
  4. package.json add some text "main": "Server.js", "type": "module", "scripts": { "start": "nodemon Server.js" }
  5. Utils/ db.js file create and connect mysqul or other database

import mysql from 'mysql'

const db = mysql.createConnection({
host: 'your_mysql_host',
user: 'your_mysql_user',
password: 'your_mysql_password',
database: 'your_mysql_database'
})

db.connect(function(err) {
iif (err) {
console.error('Error connecting to MySQL: ' + err.stack);
return;
}
console.log('Connected to MySQL as id ' + db.threadId);
})

export default db;

8.server.js work
import express from "express";
import cors from 'cors'

const app = express()
const port = 5175 ;
const localhostPort = 7175 ;
app.use(cors({
origin: [http://localhost:${localhostPort }],
methods: ['GET', 'POST', 'PUT', "DELETE"],
credentials: true
}))
app.use(express.json())

app.listen(port , () => {
console.log("Server is running")
})
app.use(cors(db));

  1. Routers file all Route here contoll.
  2. controllers fill ey all logic controll here .

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay