javascript - Error running express with node -


i'm trying start simple server on mac can access file localhost.

i have node , express installed , in server file.

var express = require('express'), app = express();  app.use(express.static(__dirname, '/'));  app.listen(8080);  console.log("app listening on port 8080"); 

when try do:

node server 

i response:

/users/mt_slasher/node_modules/express/node_modules/serve-static/index.js:47 var opts = object.create(options || null)                 ^ typeerror: object prototype may object or null: /     @ function.create (native)     @ function.servestatic (/users/mt_slasher/node_modules/express/node_modules/serve-static/index.js:47:21)     @ object.<anonymous> (/users/mt_slasher/desktop/my projects/basket/site/server.js:4:23)     @ module._compile (module.js:460:26)     @ object.module._extensions..js (module.js:478:10)     @ module.load (module.js:355:32)     @ function.module._load (module.js:310:12)     @ function.module.runmain (module.js:501:10)     @ startup (node.js:129:16)     @ node.js:814:3 

i've run same file on windows machine same files , had no problem.

after digging, found line seems main culprit:

app.use(express.static(__dirname, '/')); 

can tell me might happening?

that because passing "/" second parameter (options)

app.use(express.static(__dirname + '/')); 

see serve-static:

function servestatic(root, options) ... 

https://github.com/expressjs/serve-static/blob/master/index.js

also note better use different directory root e.g. express.static(__dirname + '/public') avoid exposing root.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -