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
1//to run : node filename.js
2const express = require('express')
3const app = express()
4const port = 3000
5
6app.get('/', (req, res) => res.send('Hello World!'))
7
8app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
9
10//visit localhost:3000
11// assuming you have done 1) npm init 2) npm install express
1// this is your code
2// ZDev1#4511 on discord if you want more help!
3// first you should install express in the terminal
4// `npm i express`.
5const express = require('express');
6const app = express();
7
8// route
9app.get('/', (req,res)=>{
10 // Sending This is the home page! in the page
11 res.send('This is the home page!');
12});
13
14// Listening to the port
15let PORT = 3000;
16app.listen(PORT)
17
18// FINISH!
1const express = require('express')
2const app = express()
3const port = 3000
4
5app.get('/', (req, res) => {
6 res.send('Hello World!')
7})
8
9app.listen(port, () => {
10 console.log(`Example app listening at http://localhost:${port}`)
11})
1const express = require("express")
2
3const app = express()
4
5app.listen(5000, () => {
6 console.log("Server has started!")
7})
1
2const express = require('express')
3const app = express()
4const port = 3000
5
6app.get('/', (req, res) => {
7 res.send('Hello World!')
8})
9
10app.listen(port, () => {
11 console.log(`Example app listening at http://localhost:${port}`)
12})
13