Answers for "express hello world"

46

express hello world

//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
3

express hello world

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}`)
})
Posted by: Guest on February-28-2021
4

sample express app

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}`))
Posted by: Guest on May-12-2020
2

express hello world example

const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors')
const bcrypt = require('bcrypt')
const jwt = require('jsonwebtoken')

//connecting to my cluster database online
mongoose.connect('mongodb+srv://username:[email protected]/databasename?retryWrites=true&w=majority', {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true });

//initializing the app 
const app = express()

//required middlware
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))

//Setting default port for the backend server
const PORT = process.env.PORT || 3333
// run in the terminal : export PORT=3333 {{justincase}}


//Test server page running
app.get('/', (req, res) => {
    res.send(`Hello World ,,,, backend is running on port ${PORT}`)
})

// Console log for terminal for server listening
app.listen(PORT, (err) => {
    if(err) return console.log(err);
    console.log(`Server listening on port ${PORT}`)
})
Posted by: Guest on June-25-2021
6

require express server.js

const express = require('express')const app = express() app.get('/', function (req, res) {  res.send('Hello World')}) app.listen(3000)
Posted by: Guest on March-19-2020
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 "Javascript"

Browse Popular Code Answers by Language