You typically want to render templates like this:
app.get('/', function(req, res){ res.render('index.ejs'); });
However you can also deliver static content – to do so use:
app.use(express.static(__dirname + '/public'));
Now everything in the /public
directory of your project will be delivered as static content at the root of your site e.g. if you place default.htm
in the public folder if will be available by visiting /default.htm
Take a look through the express API and Connect Static middleware docs for more info.
Related Posts:
- Node.exe Stuck at 100% CPU
- How do I debug error ECONNRESET in Node.js?
- How do I debug error ECONNRESET in Node.js?
- What is Express.js?
- What does body-parser do with express?
- node.js, Error: Cannot find module ‘express’
- node.js, Error: Cannot find module ‘express’
- nodemon – app crashed – waiting for file changes before starting
- “Topology was destroyed” when using MongoDB with native driver and Express.js
- Error: getaddrinfo ENOTFOUND in nodejs for get call
- nodemon not working: -bash: nodemon: command not found
- Failed to load resource: net::ERR_CONNECTION_REFUSED : Nodejs
- SyntaxError: Unexpected token import – Express
- Error: No default engine was specified and no extension was provided
- Significance of port 3000 in Express apps
- ExpressJS – throw er Unhandled error event
- NodeJS / Express: what is “app.use”?
- Why am I getting “Error socket hang up” response?
- How to Create and Use Enum in Mongoose
- First Heroku deploy failed `error code=H10`
- How to get GET (query string) variables in Express.js on Node.js?
- Error: Cannot find module ‘ejs’
- First Heroku deploy failed `error code=H10`
- In express how do I redirect a user to an external url?
- ExpressJS – throw er Unhandled error event
- ENOENT, no such file or directory
- ExpressJS : res.redirect() not working as expected?
- Push items into mongo array via mongoose
- Express.js req.body undefined
- Enabling HTTPS on express.js
- heroku is giving me Method not allowed
- passport.js passport.initialize() middleware not in use
- ExpressJS vs MeteorJS
- Cannot POST / error using express
- Route.get() requires callback functions but got a “object Undefined”
- nodemon not working properly
- npm WARN package.json: No repository field
- Advice on loopback.js vs express js
- How to update a array value in Mongoose
- How do I use HTML as the view engine in Express?
- Hapi/Joi Validation: How to process text to a specific format
- bodyParser is deprecated express 4
- Cannot access mongodb through browser – It looks like you are trying to access MongoDB over HTTP on the native driver port
- I can´t install nodemon globally, “nodemon” not recognized
- How can I update NodeJS and NPM to the next versions?
- How can I update npm itself?
- How do I update Node.js?
- How to install a previous exact version of a NPM package?
- How to fix ‘Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.’
- How to fix ‘Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.’
- How to solve npm error “npm ERR! code ELIFECYCLE”
- Start script missing error when running npm start
- How to solve npm error “npm ERR! code ELIFECYCLE”
- npm check and update package if needed
- What is the file node.exe for?
- Node.js version on the command line? (not the REPL)
- Can not find module “@angular-devkit/build-angular”
- After command npm start “Missing script:start” error
- sudo: npm: command not found
- Discord API error when trying to send one command at discord using JavaScript client
- How to resolve Nodejs: Error: ENOENT: no such file or directory
- bash: npm: command not found?
- Node.js getaddrinfo ENOTFOUND
- Node.js getaddrinfo ENOTFOUND
- Does anyone knows what “rimraf” means?
- How can I completely uninstall nodejs, npm and node in Ubuntu [closed]
- Please run `npm cache clean`
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- node.js string.replace doesn’t work?
- What is the difference between npm install and npm run build?
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- TypeError: Router.use() requires middleware function but got a Object
- Express error – TypeError: Router.use() requires middleware function but got a Object
- What is “export default” in JavaScript?
- Cannot GET / Nodejs Error
- How do I resolve “Cannot find module” error using Node.js?
- What is NODE_ENV and how to use it in Express?
- npm ERR cb() never called
- Missing write access in mac to /usr/local/lib/node_modules
- What is the difference between __dirname and ./ in node.js?
- NPM clean modules
- ‘node’ is not recognized as an internal or an external command, operable program or batch file while using phonegap/cordova
- How can the default node version be set using NVM?
- env: node: No such file or directory in mac
- mongoError: Topology was destroyed
- NPM Start not starting local server
- Error: unable to verify the first certificate in nodejs
- TypeError: Router.use() requires middleware function but got a Object
- What does the ELIFECYCLE Node.js error mean?
- What does “res.render” do, and what does the html file look like?
- How do I resolve “Cannot find module” error using Node.js?
- Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
- What is the –save option for npm install?
- how to use CryptoJS in javascript
- env: node: No such file or directory in mac
- Node Version Manager install – nvm command not found
- Error: Cannot find module ‘../lib/utils/unsupported.js’ while using Ionic
- Where is nodejs log file?