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

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

PREVIOUS NEXT
Code Example
Javascript :: react leaflet recenter map 
Javascript :: mongoose update push 
Javascript :: Summernote keyup event jquery 
Javascript :: change the way Date.now().toString() is logged 
Javascript :: Iterate Through an Array with a For Loop 
Javascript :: typescript express next middleware type 
Javascript :: shorthand if statment in js 
Javascript :: circular progress for react 
Javascript :: convert string uppercase javascript 
Javascript :: string to number 
Javascript :: math.min 
Javascript :: jquery post 
Javascript :: react chart js 
Javascript :: how to add checked in javascript 
Javascript :: str replace javascript all 
Javascript :: usereducer example 
Javascript :: javascript progress of xml http request 
Javascript :: js create element 
Javascript :: json stringify double quotes 
Javascript :: how to get the inner width of a parent div for canvas 
Javascript :: for each loop with arrowfunction 
Javascript :: leap year function javascript 
Javascript :: import library react js 
Javascript :: change focus to next field jquery after enter 
Javascript :: javascript select multiple values 
Javascript :: Map and Filter methods used together 
Javascript :: javascript copy div element content 
Javascript :: how to check if the first letter of a string is capitalized or uppercase in js 
Javascript :: reverse array without using another array js 
Javascript :: how to get sum array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =