Tuesday, April 4, 2017
Now that we have express installed let's do a little clean up and organization by creating some folders that we need. First of all create the models and controllers folder inside the app folder your folder should look like the following
Now go to the folder where you installed express, the folder should look like the following
What you want to do is copy the routes and views folders into the app folder. Your app folder should now look like the following. As the tutorial continue we will delete when we are sure we don't need it. It looks a little messy right now but when it's completed the folders will look a lot cleaner. Just igmore the .sln file. I use Visual Studio as my IDE for websites, because it's awesome.
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:
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:
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
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
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