how to start a node express server code example
Example 1: express js server
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('Some HTML
');
res.send('Even more HTML
');
});
app.listen(PORT, () => console.log(`Server is listening on port ${PORT}`));
Example 2: 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}`))
Example 3: setup node js express basic setup
npm init -y
npm i express
Example 4: require express server.js
const express = require('express')const app = express() app.get('/', function (req, res) { res.send('Hello World')}) app.listen(3000)