1/* ====== create node.js server with express.js framework ====== */
2// dependencies
3const express = require("express");
4
5const app = express();
6
7app.get("/", (req, res) => {
8 res.send("This is home page.");
9});
10
11app.post("/", (req, res) => {
12 res.send("This is home page with post request.");
13});
14
15// PORT
16const PORT = 3000;
17
18app.listen(PORT, () => {
19 console.log(`Server is running on PORT: ${PORT}`);
20});
21
22
23// ======== Instructions ========
24// save this as index.js
25// you have to download and install node.js on your machine
26// open terminal or command prompt
27// type node index.js
28// find your server at http://localhost:3000
1const express = require('express');
2const app = express();
3const PORT = process.env.PORT || 3000;
4
5app.get('/', (req, res) => {
6 res.send('<h1>Some HTML</h1>');
7 res.send('<p>Even more HTML</p>');
8});
9
10app.listen(PORT, () => console.log(`Server is listening on port ${PORT}`));
1const express = require('express')
2const app = express()
3const port = 3000
4
5app.get('/', (req, res) => res.send('Hello World!'))
6
7app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
8
1const express = require("express")
2
3const app = express()
4
5app.listen(5000, () => {
6 console.log("Server has started!")
7})
1const express = require('express')const app = express() app.get('/', function (req, res) { res.send('Hello World')}) app.listen(3000)