Answers for "nodejs app example"

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
8

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}`));
Posted by: Guest on September-29-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