Skip to content

Commit

Permalink
discard prettier changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IamLizu committed Aug 11, 2024
1 parent 6da8078 commit c9cffb1
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions en/guide/migrating-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ In version 4 you can use a variable parameter to define the path where middlewar
For example:

```js
app.use("/book/:id", (req, res, next) => {
console.log("ID:", req.params.id);
app.use('/book/:id', (req, res, next) => {
console.log('ID:', req.params.id);
next();
});
```
Expand Down Expand Up @@ -133,15 +133,15 @@ Here is an example of chained route handlers that are defined by using the `app.

```js
app
.route("/book")
.route('/book')
.get((req, res) => {
res.send("Get a random book");
res.send('Get a random book');
})
.post((req, res) => {
res.send("Add a book");
res.send('Add a book');
})
.put((req, res) => {
res.send("Update the book");
res.send('Update the book');
});
```

Expand All @@ -159,21 +159,21 @@ For example, create a router file named `birds.js` in the app directory,
with the following content:

```js
var express = require("express");
var express = require('express');
var router = express.Router();

// middleware specific to this router
router.use((req, res, next) => {
console.log("Time: ", Date.now());
console.log('Time: ', Date.now());
next();
});
// define the home page route
router.get("/", (req, res) => {
res.send("Birds home page");
router.get('/', (req, res) => {
res.send('Birds home page');
});
// define the about route
router.get("/about", (req, res) => {
res.send("About birds");
router.get('/about', (req, res) => {
res.send('About birds');
});

module.exports = router;
Expand All @@ -182,11 +182,11 @@ module.exports = router;
Then, load the router module in the app:

```js
var birds = require("./birds");
var birds = require('./birds');

// ...

app.use("/birds", birds);
app.use('/birds', birds);
```

The app will now be able to handle requests to the `/birds` and
Expand Down Expand Up @@ -326,36 +326,36 @@ Version 3 app
Consider an Express v.3 application with the following `app.js` file:

```js
var express = require("express");
var routes = require("./routes");
var user = require("./routes/user");
var http = require("http");
var path = require("path");
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');

var app = express();

// all environments
app.set("port", process.env.PORT || 3000);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(express.favicon());
app.use(express.logger("dev"));
app.use(express.logger('dev'));
app.use(express.methodOverride());
app.use(express.session({ secret: "your secret here" }));
app.use(express.session({ secret: 'your secret here' }));
app.use(express.bodyParser());
app.use(app.router);
app.use(express.static(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, 'public')));

// development only
if (app.get("env") === "development") {
if (app.get('env') === 'development') {
app.use(express.errorHandler());
}

app.get("/", routes.index);
app.get("/users", user.list);
app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get("port"), () => {
console.log("Express server listening on port " + app.get("port"));
http.createServer(app).listen(app.get('port'), () => {
console.log('Express server listening on port ' + app.get('port'));
});
```

Expand Down Expand Up @@ -440,61 +440,61 @@ Then, remove invalid code, load the required middleware, and make other
changes as necessary. The `app.js` file will look like this:

```js
var http = require("http");
var express = require("express");
var routes = require("./routes");
var user = require("./routes/user");
var path = require("path");

var favicon = require("serve-favicon");
var logger = require("morgan");
var methodOverride = require("method-override");
var session = require("express-session");
var bodyParser = require("body-parser");
var multer = require("multer");
var errorHandler = require("errorhandler");
var http = require('http');
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var path = require('path');

var favicon = require('serve-favicon');
var logger = require('morgan');
var methodOverride = require('method-override');
var session = require('express-session');
var bodyParser = require('body-parser');
var multer = require('multer');
var errorHandler = require('errorhandler');

var app = express();

// all environments
app.set("port", process.env.PORT || 3000);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
app.use(favicon(path.join(__dirname, "/public/favicon.ico")));
app.use(logger("dev"));
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
app.use(logger('dev'));
app.use(methodOverride());
app.use(
session({
resave: true,
saveUninitialized: true,
secret: "uwotm8",
secret: 'uwotm8',
})
);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(multer());
app.use(express.static(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, 'public')));

app.get("/", routes.index);
app.get("/users", user.list);
app.get('/', routes.index);
app.get('/users', user.list);

// error handling middleware should be loaded after the loading the routes
if (app.get("env") === "development") {
if (app.get('env') === 'development') {
app.use(errorHandler());
}

var server = http.createServer(app);
server.listen(app.get("port"), () => {
console.log("Express server listening on port " + app.get("port"));
server.listen(app.get('port'), () => {
console.log('Express server listening on port ' + app.get('port'));
});
```

<div class="doc-box doc-info" markdown="1">
Unless you need to work directly with the `http` module (socket.io/SPDY/HTTPS), loading it is not required, and the app can be simply started this way:

```js
app.listen(app.get("port"), () => {
console.log("Express server listening on port " + app.get("port"));
app.listen(app.get('port'), () => {
console.log('Express server listening on port ' + app.get('port'));
});
```

Expand Down Expand Up @@ -595,17 +595,17 @@ delete the line that says `module.exports = app;` at the end of the
`app.js` file, then paste the following code in its place:

```js
app.set("port", process.env.PORT || 3000);
app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get("port"), () => {
debug("Express server listening on port " + server.address().port);
var server = app.listen(app.get('port'), () => {
debug('Express server listening on port ' + server.address().port);
});
```

Ensure that you load the `debug` module at the top of the `app.js` file by using the following code:

```js
var debug = require("debug")("app4");
var debug = require('debug')('app4');
```

Next, change `"start": "node ./bin/www"` in the `package.json` file to `"start": "node app.js"`.
Expand Down

0 comments on commit c9cffb1

Please sign in to comment.