Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp push #340

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 02-nodejs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const express = require('express');
const bodyParser = require('body-parser'); // Import body-parser

const app = express();
const port = 3000;
let arr = [];

app.use(bodyParser.json()); // Enable parsing of JSON data
app.use(bodyParser.urlencoded({ extended: true })); // Enable parsing of URL-encoded form data

function handlereq(req, res) {
res.send(arr);
}

function handlereq2(req, res) {
arr.push(req.body); // Push the parsed request body into the arr array
res.send("ok");
}
// chilling
app.get('/', handlereq);
app.post('/', handlereq2);

app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
100 changes: 84 additions & 16 deletions 02-nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion 02-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "02-nodejs",
"version": "1.0.0",
"description": "",
"description": "In this series of assignments, you are going to create native HTTP servers in Node.js which will handle different kinds of application logics.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand All @@ -21,7 +21,11 @@
"testTimeout": 10000
},
"dependencies": {
"body-parser": "^1.20.2",
"express": "^4.18.2",
"uuid": "^9.0.0"
},
"directories": {
"test": "tests"
}
}