I want to convert the string to JSON and vice versa. I am using JSON.Stringfy in router.js below. Do I need to have anything particular npm added to project use the JSON.Stringfy function?
Below is the code:
**app.js** file(main file executed by node.exe)
app.get('/about',routes.about);-->calling it using **http://localhost:3000/about**
**routers.js**
var User = {
'Name' :'',
'EmailId':'',
'Phone':'',
'Address':'',
'favouriteSport':''
}
exports.about = function(req,res){
res.send("Wele to sports maniac" + JSON.Stringfy(User));
}
seeing below exception:
TypeError: JSON.Stringfy is not a function
at exports.about (F:\Personal Filess\Google Drive\Software Tools\Projects\routes\router.js:17:45)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
at next (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
at F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:277:22
at Function.process_params (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:330:12)
at next (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:271:10)
at expressInit (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\middleware\init.js:33:5)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
I want to convert the string to JSON and vice versa. I am using JSON.Stringfy in router.js below. Do I need to have anything particular npm added to project use the JSON.Stringfy function?
Below is the code:
**app.js** file(main file executed by node.exe)
app.get('/about',routes.about);-->calling it using **http://localhost:3000/about**
**routers.js**
var User = {
'Name' :'',
'EmailId':'',
'Phone':'',
'Address':'',
'favouriteSport':''
}
exports.about = function(req,res){
res.send("Wele to sports maniac" + JSON.Stringfy(User));
}
seeing below exception:
TypeError: JSON.Stringfy is not a function
at exports.about (F:\Personal Filess\Google Drive\Software Tools\Projects\routes\router.js:17:45)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
at next (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
at F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:277:22
at Function.process_params (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:330:12)
at next (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\index.js:271:10)
at expressInit (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\middleware\init.js:33:5)
at Layer.handle [as handle_request] (F:\Personal Filess\Google Drive\Software Tools\Projects\node_modules\express\lib\router\layer.js:95:5)
Share
Improve this question
edited Nov 18, 2015 at 3:57
Swaraj Giri
4,0372 gold badges30 silver badges45 bronze badges
asked Nov 18, 2015 at 3:13
Haridev NirgudeHaridev Nirgude
431 silver badge6 bronze badges
0
3 Answers
Reset to default 2ItJSON.stringify
not JSON.Stringfy
.
Pro tip - Next time you see a error message on the lines of xyz is not a function
try googling that function name.
https://developer.mozilla/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
I think you have the function name spellt wrong, It's Stringify.
After a lot of research found the JSON npm module. JSON2 is a npm module which is I am using.
Just run the mand in node.js mand prompt :npm install json2 -g Then to add the node module to project run: npm install JSON2 --save
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745319889a4622395.html
评论列表(0条)