how to create an express project code example
Example 1: 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!
Example 2: initialize express app
npx express-generator
Example 3: generate express app
$ npx express-generator
Example 4: create node project
#1. server.js
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.status(200).send('Hello World!');
});
var port = process.env.PORT || 3000;
var server = app.listen(port, function() {
console.log('Express server listening on port ' + port);
});
open cmd run server.js
"node server.js"
log:Express server listening on port 3000
& then
open link "http://localhost:3000/" in your browser and show result.