create express server in node js code example
Example 1: how to make an express server
const express = require('express');
const app = express();
app.get('/', (req,res)=>{
res.send('This is the home page!');
});
let PORT = 3000;
app.listen(PORT)
Example 2: 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})
})
Example 3: create express server local
'use strict';
const express = require('express');
const app = express();
app.use(express.static('public'));
app.use(express.json());
app.get('/', function(req,res){
res.send('This is the Homepage');
});
app.listen(3000);