1
2const express = require('express')
3const app = express()
4const port = 3000
5
6app.get('/', (req, res) => {
7 res.send('Hello World!')
8})
9
10app.listen(port, () => {
11 console.log(`Example app listening at http://localhost:${port}`)
12})
13
14
1const express = require('express');
2const app = express();
3const port = 3000;
4
5app.get('/', (req, res) => {
6 res.send('Hello World!')
7});
8
9app.listen(port, () => {
10 console.log(`App listening at http://localhost:${port}`)
11});
1Connect With mongodb, cors , dotenv, express
2
3const express = require('express');
4const cors = require('cors')//cors for own server connected with own
5const app = express();
6require("dotenv").config();//dotenv config
7const port = process.env.PORT || 5000;
8
9//Middleware
10app.use(cors());
11app.use(express.json());
12
13const { MongoClient } = require('mongodb');
14const uri = `mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASS}@cluster0.vdirb.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`;
15const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
16
17async function run() {
18 try {
19 await client.connect();
20 const database = client.db("insertDB");
21 const servicesCollection = database.collection("volunteers");
22
23
24 }
25 finally {
26 // await client.close();
27 }
28 }
29 run().catch(console.dir);
30
31
32
33app.get('/',(req,res) =>{
34 res.send('Server is ok')
35});
36
37app.listen(port, () =>{
38 console.log('Port is Ok');
39})
1Express is a minimal and flexible Node.js web application framework
2that provides a robust set of features for web and mobile
3applications.
1Express.js, or simply Express, is a web application framework for Node.js,
2released as free and open-source software under the MIT License.
3
4It is designed for building web applications and APIs.
5It has been called the de facto standard server framework for Node.js.