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
- How can I update npm itself?
- 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
- npm check and update package if needed
- Error: Can’t set headers after they are sent to the client
- Client on Node.js: Uncaught ReferenceError: require is not defined
- TypeError: Router.use() requires middleware function but got a Object
- Cannot GET / Nodejs Error
- How do I resolve “Cannot find module” error using Node.js?
- npm ERR cb() never called
- env: node: No such file or directory in mac
- Error: unable to verify the first certificate in nodejs
- Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
- how to use CryptoJS in javascript
- nodemon not found in npm
- How can I wait In Node.js (JavaScript)? l need to pause for a period of time
- How to change to an older version of Node.js
- npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY
- Error: EACCES: permission denied
- What does the ELIFECYCLE Node.js error mean?
- How to write a .nvmrc file which automatically change node version
- node.js: how to use setInterval and clearInterval?
- Git Bash Command on Windows, yarn command not found
- What is Procfile? and Web and Worker
- What is Procfile? and Web and Worker
- What is process.env.PORT in Node.js?
- Cannot find module ‘internal/util/types’
- I am getting error in console “You need to enable JavaScript to run this app.” reactjs
- Passport and connect-flash: req.flash is not a function
- Error: Cannot find module ‘webpack’
- E11000 duplicate key error index in mongodb mongoose
- Node.js: Difference between req.query[] and req.params
- sequelize “findbyid” is not a function but apparently “findAll” is
- Nginx upstream prematurely closed connection while reading response header from upstream, for large requests
- AWS lambda function error – Unable to import module ‘index’: Error
- How to install npm peer dependencies automatically?
- How to Reinstall Broken npm
- What is javascript runtime..?
- How to update a record using sequelize for node?
- Block-scoped declarations not yet supported outside strict mode
- Cannot npm install due to node-gyp: binding.gyp not found
- Downgrade npm to an older version
- npm install resulting in ‘ENOENT: no such file or directory’
- How to access the request body when POSTing using Node.js and Express?
- SyntaxError: expected expression, got ‘<'
- How to create a directory if it doesn’t exist using Node.js
- path.join vs path.resolve with __dirname
- Npm Error – Windows NT – How to resolve
- Node.js – EJS – including a partial
- How to properly upgrade node using nvm
- How to sort a collection by date in MongoDB?
- npm update check failed
- Forwarding port 80 to 8080 using NGINX
- How to drop a database with Mongoose?
- npm init not working and getting stuck on version
- GYP ERR! build error. stack Error: ‘make’ failed with exit code 2