Answers for "how to make a server with express"

53

express.js server

/* ====== create node.js server with express.js framework ====== */
// dependencies
const express = require("express");

const app = express();

app.get("/", (req, res) => {
   res.send("This is home page.");
});

app.post("/", (req, res) => {
   res.send("This is home page with post request.");
});

// PORT
const PORT = 3000;

app.listen(PORT, () => {
   console.log(`Server is running on PORT: ${PORT}`);
});


// ======== Instructions ========
// save this as index.js
// you have to download and install node.js on your machine
// open terminal or command prompt
// type node index.js
// find your server at http://localhost:3000
Posted by: Guest on January-13-2021
49

express js basic example

//to run : node filename.js
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}`))

//visit localhost:3000
// assuming you have done 1) npm init 2) npm install express
Posted by: Guest on July-17-2020
6

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!
Posted by: Guest on July-03-2020
0

js express server

const http = require('http')
const express = require('express')

const app = express()
const server = http.Server(app)
app.set('port', 8888)
server.listen(8888)

app.get('/', (req, res) => {
  res.json({teste: true})
})
Posted by: Guest on January-30-2021
0

create express server local

// create directory

//npm init -y
//npm i express --save

//create public directory
//create server.js

// <---- In the server js file --->

'use strict';

const express = require('express');
const app = express();
app.use(express.static('public'));// to connect with frontend html
app.use(express.json());//body parse

app.get('/', function(req,res){
	res.send('This is the Homepage');
  	//res.sendFile('index.html');
});

app.listen(3000);
Posted by: Guest on January-07-2021

Code answers related to "how to make a server with express"

Code answers related to "Javascript"

Browse Popular Code Answers by Language