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

javascript express server

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

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
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

Express Server

const express = require("express")

const app = express()

app.listen(5000, () => {
	console.log("Server has started!")
})
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 :: convert a string to object javascript 
Javascript :: import image as component react 
Javascript :: js platformer 
Javascript :: mdn rest 
Javascript :: vuejs check object key exist 
Javascript :: settimeout function es6 
Javascript :: The jQuery noConflict() Method 
Javascript :: how to enter javascript in html 
Javascript :: (Unauthorized) not authorized on admin to execute command 
Javascript :: how to render react native app under the status bar 
Javascript :: sequelize desc does not exist 
Javascript :: loop through dom elements javascript 
Javascript :: react-file-base64 
Javascript :: adding styling to element using javascript 
Javascript :: js get class property 
Javascript :: json.stringify vs json.parse 
Javascript :: upload preview image jquery 
Javascript :: expose deployment nodeport command 
Javascript :: how to get selected value of a dropdown menu in reactjs 
Javascript :: on load page javascript 
Javascript :: how to remove duplicate object in array javascript 
Javascript :: change image src using jquery 
Javascript :: javascript currency format 
Javascript :: run onclick function once js 
Javascript :: javascript two decimal places after division 
Javascript :: vue get if checkbox is checked 
Javascript :: javascript iterate over map keys 
Javascript :: axios middleware 
Javascript :: oneerror javascript image 
Javascript :: validationResult is not defined 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =