זהו נושא דיון מלווה לערך המקורי שב־https://www.tocode.co.il/bundles/frontend/lessons/serverside
זה לא מצליח לי, התיקייה נמצאת בניתוב c:\temp וקוראים לה node
צרפתי העתקה של הcmd.
Microsoft Windows [Version 10.0.19041.388]
© 2020 Microsoft Corporation. All rights reserved.
C:\Users\LENOVO>cd C:\temp\node\
C:\temp\node>npm init -y
Wrote to C:\temp\node\package.json:
{
“name”: “node”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”
},
“keywords”: [],
“author”: “”,
“license”: “ISC”
}
C:\temp\node>npm install --save express vody-parser
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/vody-parser - Not found
npm ERR! 404
npm ERR! 404 ‘vody-parser@latest’ is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\LENOVO\AppData\Roaming\npm-cache_logs\2020-08-25T12_53_00_850Z-debug.log
C:\temp\node>
מה השגיאה? למה זה לא עובד?
תודה
רק עכשיו אני רואה את הקישור. ניסיתי להכנס אליו הוא כותב לי “שגיאה”,
אולי זה מה שחוסם אותו, אם כן מה אפשר לעשות?
תודה
הי
נדמה לי שיש לך שגיאה בשורת הפקודה - צריך להיות body-parser
תודה, זה באמת מה שתקע אותו.
המשכתי קצת והוא נתקע עוד פעם בהכנסת נתונים. מצורף העתקה של 2 חלונות שורות הפקודה, אשמח אם תבדוק מה הבעיה.
Microsoft Windows [Version 10.0.19041.388]
© 2020 Microsoft Corporation. All rights reserved.
C:\Users\LENOVO>cd C:\temp\node
C:\temp\node>node server.js
SyntaxError: Unexpected token ’ in JSON at position 0
at JSON.parse ()
at createStrictSyntaxError (C:\temp\node\node_modules\body-parser\lib\types\json.js:158:10)
at parse (C:\temp\node\node_modules\body-parser\lib\types\json.js:83:15)
at C:\temp\node\node_modules\body-parser\lib\read.js:121:18
at invokeCallback (C:\temp\node\node_modules\raw-body\index.js:224:16)
at done (C:\temp\node\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\temp\node\node_modules\raw-body\index.js:273:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Microsoft Windows [Version 10.0.19041.388]
© 2020 Microsoft Corporation. All rights reserved.
C:\Users\LENOVO>curl localhost:8080/users
{“users”:[{“name”:“hello”},{“name”:“yehudit”}]}
C:\Users\LENOVO>curl -H “Content-Type: application/json” -d ‘{“name”:“jim”}’ localhost:8080/users
SyntaxError: Unexpected token ' in JSON at position 0
at JSON.parse (<anonymous>)
at createStrictSyntaxError (C:\temp\node\node_modules\body-parser\lib\types\json.js:158:10)
at parse (C:\temp\node\node_modules\body-parser\lib\types\json.js:83:15)
at C:\temp\node\node_modules\body-parser\lib\read.js:121:18
at invokeCallback (C:\temp\node\node_modules\raw-body\index.js:224:16)
at done (C:\temp\node\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\temp\node\node_modules\raw-body\index.js:273:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
C:\Users\LENOVO>
תודה
הי
נראה שסימן הגרש שכתבת לא מזוהה על ידי Windows ולכן בטעות עובר לפקודה curl.
אולי לא עבדנו על אותה גירסת ווינדוס או שמשהו אחר בהגדרות המחשב שלך שונה ממה שהיה אצלי בהקלטה.
בכל מקרה נסי בשלב ראשון לוותר על הגרש בודד בשני הצדדים של הסוגריים המסולסלים וספרי אם זה משפר את המצב
זה באמת היה הבעיה, תודה
מאיפה אפשר להוריד את הקבצים של מהלך השיעור (תיקיות ה- before/after ?)
הי
הכל כאן:
היי ינון - תודה לקורס!
פעלתי לפי ההוראות, ולא הצלחתי לקבל מערך חדש : ע"פ הפקודה
curl -H “Content-Type: application/json” -d ‘{ “name” : “jim” }’ localhost:8080/users
יש לי ווינדוס 10, האם עדיין זה אומר שאני צריך להוריד ולהתקין את curl ?
הי נדמה לי שאחרי ה -d
גם צריך להשתמש במרכאות כפולות (אתה השתמשת בבודדות). אני רואה שגם בדף השיעור בקורס עשיתי את הטעות הזאת אז אתקן גם שם
בכל מקרה התחביר הנכון הוא:
curl -H "Content-Type: application/json" -d "{ \"name\": \"jim\" }" localhost:8080/user