File tree Expand file tree Collapse file tree 4 files changed +81
-0
lines changed Expand file tree Collapse file tree 4 files changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ const express = require ( "express" ) ;
3
+ const app = express ( ) ;
4
+ app . use ( express . json ( ) ) ;
5
+
6
+ app . post ( "/info" , ( req , res ) => {
7
+ console . log ( req . body ) ;
8
+ res . json ( req . body ) ;
9
+ } ) ;
10
+
11
+ app . listen ( 3000 , ( ) => {
12
+ console . log ( "Application started on port 3000" ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ const express = require ( "express" ) ;
3
+ const path = require ( "path" ) ;
4
+
5
+ const app = express ( ) ;
6
+ app . use ( express . static ( "public" ) ) ;
7
+ app . use ( express . urlencoded ( { extended : true } ) ) ;
8
+
9
+ app . get ( "/" , ( req , res ) => {
10
+
11
+ res . sendFile ( path . join ( __dirname , "public" , "index.html" ) ) ;
12
+ } ) ;
13
+
14
+ app . post ( "/message" , ( req , res ) => {
15
+
16
+ res . set ( { "Content-Type" : "text/plain; charset=utf-8" } ) ;
17
+
18
+ let name = req . body . name ;
19
+ let message = req . body . message ;
20
+ let output = `${ name } says: ${ message } ` ;
21
+
22
+ res . send ( output ) ;
23
+ } ) ;
24
+
25
+
26
+ app . listen ( 3000 , ( ) => {
27
+ console . log ( "Application started on port 3000" ) ;
28
+ } ) ;
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ const axios = require ( "axios" ) ;
3
+
4
+ async function makePostRequest ( ) {
5
+ let params = {
6
+ first_name : "John" ,
7
+ last_name : "Doe" ,
8
+ email : "gardener"
9
+ } ;
10
+
11
+ let res = await axios . post ( "http://localhost:3000/info/" , params ) ;
12
+
13
+ console . log ( `Status code: ${ res . status } ` ) ;
14
+ console . log ( `Status text: ${ res . statusText } ` ) ;
15
+ console . log ( `Request method: ${ res . request . method } ` ) ;
16
+ console . log ( `Path: ${ res . request . path } ` ) ;
17
+ console . log ( res . data ) ;
18
+ }
19
+
20
+ makePostRequest ( ) ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Form</ title >
6
+ </ head >
7
+ < body >
8
+ < form action ="message " method ="post ">
9
+ < div >
10
+ < label > Name:</ label >
11
+ < input type ="text " name ="name ">
12
+ </ div >
13
+ < div >
14
+ < label > Message</ label >
15
+ < input type ="text " name ="message ">
16
+ </ div >
17
+ < button type ="submit "> Send</ button >
18
+ </ form >
19
+ </ body >
20
+ </ html >
You can’t perform that action at this time.
0 commit comments