Skip to main content
added 11 characters in body; edited title
Source Link
niutech
  • 30.2k
  • 15
  • 102
  • 110

Save a jsonJSON file to server in express (node)

Having this function in express that writes a jsonJSON file on a folder

var savingtheJson=function(path, jsonObject, callback){ jsonfile.writeFile(file2, jsonO, callback); } 

I will like to know how can I access/read this file from the browser once is saved.

ifIf I do this:

savingtheJson('/json/myfile.json', jsonObj, function(){ console.log("done it!"); }); 

When I go to the browser and I type: localhost:8080/json/myfile.json Of

http://localhost:8080/json/myfile.json 

Of course I get an error from express "Cannot Get ...." cause I think is trying to resolve it like an specific request

How can I store this file into the static folder declared for this goal (app.use(express.static(__dirname + '/public')app.use(express.static(__dirname + '/public'))?

How can I access this file once is saved?

Save a json file to server in express (node)

Having this function in express that writes a json file on a folder

var savingtheJson=function(path, jsonObject, callback){ jsonfile.writeFile(file2, jsonO, callback); } 

I will like to know how can I access/read this file from the browser once is saved.

if I do this:

savingtheJson('/json/myfile.json', jsonObj, function(){ console.log("done it!"); }); 

When I go to the browser and I type: localhost:8080/json/myfile.json Of course I get an error from express "Cannot Get ...." cause I think is trying to resolve it like an specific request

How can I store this file into the static folder declared for this goal (app.use(express.static(__dirname + '/public'))?

How can I access this file once is saved?

Save a JSON file to server in express (node)

Having this function in express that writes a JSON file on a folder

var savingtheJson=function(path, jsonObject, callback){ jsonfile.writeFile(file2, jsonO, callback); } 

I will like to know how can I access/read this file from the browser once is saved.

If I do this:

savingtheJson('/json/myfile.json', jsonObj, function(){ console.log("done it!"); }); 

When I go to the browser and I type:

http://localhost:8080/json/myfile.json 

Of course I get an error from express "Cannot Get ...." cause I think is trying to resolve it like an specific request

How can I store this file into the static folder declared for this goal (app.use(express.static(__dirname + '/public'))?

How can I access this file once is saved?

Source Link
Frnnd Sgz
  • 328
  • 1
  • 4
  • 19

Save a json file to server in express (node)

Having this function in express that writes a json file on a folder

var savingtheJson=function(path, jsonObject, callback){ jsonfile.writeFile(file2, jsonO, callback); } 

I will like to know how can I access/read this file from the browser once is saved.

if I do this:

savingtheJson('/json/myfile.json', jsonObj, function(){ console.log("done it!"); }); 

When I go to the browser and I type: localhost:8080/json/myfile.json Of course I get an error from express "Cannot Get ...." cause I think is trying to resolve it like an specific request

How can I store this file into the static folder declared for this goal (app.use(express.static(__dirname + '/public'))?

How can I access this file once is saved?