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

express js server

const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;

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

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

create express js project

$ npx express-generator
Comment

require express server.js

const express = require('express')const app = express() app.get('/', function (req, res) {  res.send('Hello World')}) app.listen(3000)
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 :: javascript convert to two decimal places 
Javascript :: stopped typing jquery 
Javascript :: Add event listener to multiple buttons with the same class 
Javascript :: sort an array by characters length in js 
Javascript :: how to swap two elements in an array js 
Javascript :: ng serve local network 
Javascript :: jquery on checkbox checked es6 
Javascript :: javascript wait 10 seconds 
Javascript :: ajax each function 
Javascript :: js vanilla when i remove one object it removes all of them 
Javascript :: downgrade react version to 17 
Javascript :: electron communicate between main and renderer 
Javascript :: jquery find type submit 
Javascript :: setlocalstorage 
Javascript :: js insert string at position 
Javascript :: how to get element in iframe using javascript 
Javascript :: v-select on change 
Javascript :: change text of span js html 
Javascript :: convert csv to json python using pandas 
Javascript :: retrieve object array value based on key 
Javascript :: jquery trim 
Javascript :: es6 get value by key 
Javascript :: placeholder in angular 9 select with working required 
Javascript :: node crypto hmac sha256 
Javascript :: random hexadecimal character js 
Javascript :: nuxt redirect traffic from http to https 
Javascript :: js remove all objects from array where value 
Javascript :: location.reload sweetalert 
Javascript :: javascript get timestamp 
Javascript :: scroll to top in jquery 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =