1//to run : node filename.js
2const express = require('express')
3const app = express()
4const port = 3000
5
6app.get('/', (req, res) => res.send('Hello World!'))
7
8app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
9
10//visit localhost:3000
11// assuming you have done 1) npm init 2) npm install express
1const express = require('express')
2const app = express()
3const port = 3000
4
5app.get('/', (req, res) => res.send('Hello World!'))
6
7app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
8
1const express = require('express');
2const bodyParser = require('body-parser');
3const mongoose = require('mongoose');
4const cors = require('cors')
5const bcrypt = require('bcrypt')
6const jwt = require('jsonwebtoken')
7
8//connecting to my cluster database online
9mongoose.connect('mongodb+srv://username:password@clustername.elei8.mongodb.net/databasename?retryWrites=true&w=majority', {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true });
10
11//initializing the app
12const app = express()
13
14//required middlware
15app.use(cors())
16app.use(bodyParser.json())
17app.use(bodyParser.urlencoded({ extended: false }))
18
19//Setting default port for the backend server
20const PORT = process.env.PORT || 3333
21// run in the terminal : export PORT=3333 {{justincase}}
22
23
24//Test server page running
25app.get('/', (req, res) => {
26 res.send(`Hello World ,,,, backend is running on port ${PORT}`)
27})
28
29// Console log for terminal for server listening
30app.listen(PORT, (err) => {
31 if(err) return console.log(err);
32 console.log(`Server listening on port ${PORT}`)
33})
34
1const express = require('express')const app = express() app.get('/', function (req, res) { res.send('Hello World')}) app.listen(3000)