abijuru-wise-rest-api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +29 -0
  2. package/package.json +15 -0
package/index.js ADDED
@@ -0,0 +1,29 @@
1
+ const express = require("express");
2
+ const app = express();
3
+ const PORT = 3000;
4
+
5
+ app.use(express.json());
6
+
7
+ let products = [
8
+ { id: 1, name: "Laptop", price: 250000 },
9
+ { id: 2, name: "Phone", price: 180000 }
10
+ ];
11
+
12
+ app.get("/products", (req, res) => {
13
+ res.json(products);
14
+ });
15
+
16
+ app.post("/products", (req, res) => {
17
+ const newProduct = {
18
+ id: products.length + 1,
19
+ name: req.body.name,
20
+ price: req.body.price
21
+ };
22
+
23
+ products.push(newProduct);
24
+ res.status(201).json(newProduct);
25
+ });
26
+
27
+ app.listen(PORT, () => {
28
+ console.log(`Server running on http://localhost:${PORT}`);
29
+ });
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "abijuru-wise-rest-api",
3
+ "version": "1.0.0",
4
+ "description": "simple Node.js REST API for beginners",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js"
8
+ },
9
+ "keywords": ["api", "node", "express", "rest"],
10
+ "author": "Serge Wise",
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "express": "^5.2.1"
14
+ }
15
+ }