json - Get absolute URL path using Node Js Express and possibly ajax -
hi relatively new node.js , have been reading lot topic. @ impasse. trying absolute path of file:
example: https://localhost:8080.../public/img/apple.jpg
instead getting nothing printed in console or usual:
/public/img,apple.jpg
below javsscript file run in node. have tried few things apologize if looks "newbie" believe these closest.
note: have tried alot inside 'app.get' function never seems print out console.
var fs = require('fs'); var http = require("http"); var http = require("http"); var url = require("url"); var req = require('request') http.createserver(function (request, response) { response.writehead(200, {'content-type': 'text/plain'}); var express = require('express'); var app = express(); var path = require('path'); app.get('../img/apple.jp', function(req, res) { var dir = req.params.dir; console.log(req.originalurl) var pathname = url.parse(req.url).pathname; var fullurl = req.protocol + '://' + req.originalurl; console.log("request " + pathname + " received."); console.log("test" + fullurl); // res.sendfile(path.join(__dirname + 'sliderimages.json')); var fullurl = req.protocol + '://' + req.get('host') + req.originalurl; console.log(fullurl); });
some of following links have went followed:
- https://nodejs.org/api/path.html
- get application full path in node.js
- how path current script node.js?
- how full url in express?
i have went others believe these closest have read. number 4. on how accomplish appreciated, have tried multiple things 4 hours , cannot seem work. in advance.
- you forgot
g
in../img/apple.jp
. - you have required
http
twice. - you have
req
object in app.get userequest
instead. (be careful copy/past of other's code)
Comments
Post a Comment