Now go to the folder where you installed express, the folder should look like the following
We now have to tell express that we moved the routes and views folders, we do this by changing the configuration in the app.js file. Open the app.js file in the express root folder with a text editor and look for the line app.set('views', path.join(__dirname, 'views')); and change it to
app.set('views', path.join(__dirname, 'app', 'views'));
now look for the routes configuration with the lines
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
change it to
var indexRouter = require('./app/routes/index');
var users Router = require('./app/routes/users');
The completed code should look like the following:
var createError = require('http-errors'); var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); var logger = require('morgan'); var indexRouter = require('./app/routes/index'); var usersRouter = require('./app/routes/users'); var app = express(); // view engine setup app.set('views', path.join(__dirname,'app', 'views')); app.set('view engine', 'jade'); app.use(logger('dev')); app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', indexRouter); app.use('/users', usersRouter); // catch 404 and forward to error handler app.use(function(req, res, next) { next(createError(404)); }); // error handler app.use(function(err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page res.status(err.status || 500); res.render('error'); }); module.exports = app;
Now run express by typing npm start and you will see that it still works!
Type http://localhost:3000 into your browser
Posts In The AngularJS SPA Application Series:
- Setting Up Angular-Seed
- Preparing Angular-Seed For The Shopping List Application
- Refactor Code to Not Use Global Variables (Shopping List App)
- Installing MongoDB
- Create a MongoDB Configuration FIle
- Install mongoDB as a Windows Service
- Installing Express generator
- Installing ExpressJS Application Server
- Creating The SPA Project Folder Structure
- Setup Express To Serve Static Files
- Setup The Shopping Application For Heroku And Testing It Locally
- Deploy Shopping List Application To Heroku
- Install RoboMongo GUI for MongoDB
Mua vé tại đại lý vé máy bay Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ Vietnam Airline
đăng ký về việt nam ở mỹ
bay từ nhật về việt nam
vé máy bay từ đức về việt nam
vé máy bay từ canada về việt nam
Có chuyến bay từ Hàn Quốc về Việt Nam không
chuyen bay danh cho chuyen gia