From 3c54220a3495a7a2cdf580c3289ee37e835c0190 Mon Sep 17 00:00:00 2001 From: Hamza Date: Sun, 31 Jul 2016 13:14:05 +0100 Subject: [PATCH] Use node's `path.join` in examples (#3046) closes #3046 --- examples/static-files/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/static-files/index.js b/examples/static-files/index.js index c3b1659d861..04ad8693546 100644 --- a/examples/static-files/index.js +++ b/examples/static-files/index.js @@ -3,6 +3,7 @@ */ var express = require('../..'); +var path = require('path'); var logger = require('morgan'); var app = express(); @@ -16,7 +17,7 @@ app.use(logger('dev')); // that you pass it. In this case "GET /js/app.js" // will look for "./public/js/app.js". -app.use(express.static(__dirname + '/public')); +app.use(express.static(path.join(__dirname, 'public'))); // if you wanted to "prefix" you may use // the mounting feature of Connect, for example @@ -24,17 +25,17 @@ app.use(express.static(__dirname + '/public')); // The mount-path "/static" is simply removed before // passing control to the express.static() middleware, // thus it serves the file correctly by ignoring "/static" -app.use('/static', express.static(__dirname + '/public')); +app.use('/static', express.static(path.join(__dirname, 'public'))); // if for some reason you want to serve files from // several directories, you can use express.static() // multiple times! Here we're passing "./public/css", // this will allow "GET /style.css" instead of "GET /css/style.css": -app.use(express.static(__dirname + '/public/css')); +app.use(express.static(path.join(__dirname, 'public', 'css'))); app.listen(3000); console.log('listening on port 3000'); console.log('try:'); console.log(' GET /hello.txt'); console.log(' GET /js/app.js'); -console.log(' GET /css/style.css'); +console.log(' GET /css/style.css'); \ No newline at end of file