Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to make an express server

// this is your code
// ZDev1#4511 on discord if you want more help!
// first you should install express in the terminal
// `npm i express`.
const express = require('express');
const app = express();

// route
app.get('/', (req,res)=>{
  // Sending This is the home page! in the page
  res.send('This is the home page!');
});

// Listening to the port
let PORT = 3000;
app.listen(PORT)

// FINISH!
Comment

starting express server

const express = require("express");
const cors = require("cors");
require("dotenv").config();
const port = process.env.PORT || 5000;
const app = express();

//middle ware
app.use(cors());
app.use(express.json());

app.get("/", (req, res) => {
  res.send("server is up");
});

app.listen(port, () => {
  console.log("server is running");
});
Comment

Express Server

const express = require("express")

const app = express()

app.listen(5000, () => {
	console.log("Server has started!")
})
Comment

simple express server

const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');

app.use(bodyParser.json());
const PORT = process.env.PORT || 3000;

app.use(bodyParser.json());

//connecting to db
try {
    mongoose.connect('mongodb://localhost/YOUR_DB_NAME', {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      	useCreateIndex: true,
      }, () =>
      console.log("connected"));
  } catch (error) {
    console.log("could not connect");
  }

app.get('/', (req, res) => {
  res.send('<h1>Some HTML</h1>');
  res.send('<p>Even more HTML</p>');
});



app.listen(PORT, () => console.log(`Server is listening on port ${PORT}`));
Comment

simple expressjs example server


const express = require('express')
const app = express()
const port = 9000


app.get('/',(req,res) => {
	try {
    	res.json({message:"server is ready at 9000 port "})
    } catch (error) {
    	consolelog(error)
      	res.sendStatus(500)
    }
})


app.listen(port,() => console.log('server is runing at 9000'))
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to validate password and confirm password on react form hook 
Javascript :: google sheets get ranges 
Javascript :: pass text and variable in alert javascript 
Javascript :: return statement javascript 
Javascript :: react native add bottom tab and drawer menu 
Javascript :: return object from map javascript 
Javascript :: hide html elements 
Javascript :: myFunction with param on addEventListner 
Javascript :: flatlist inside flatlist react native 
Javascript :: node http2 post 
Javascript :: how to give path of file which in directory in require_once 
Javascript :: _.escape underscore 
Javascript :: express proxy 
Javascript :: js lambda 
Javascript :: Add jquery in extension 
Javascript :: pwa cache viewer 
Javascript :: javascript index of biggest number 
Javascript :: for of loop ecmascript6 
Javascript :: file upload nest 
Javascript :: JavaScript try...catch Statement 
Javascript :: how to convert string to toggle case in javascript 
Javascript :: javascript js ternary operater 
Javascript :: loops javascript 
Javascript :: javascript get all elements of an id 
Javascript :: tinymce editor description value is not getting onclick js 
Javascript :: useWidthSize 
Javascript :: repeat call n times in js 
Javascript :: flutter local json storage 
Javascript :: competitive programming in javascript 
Javascript :: loading screen html css js 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =