本文整理汇总了TypeScript中mongoose.connect函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connect函数的具体用法?TypeScript connect怎么用?TypeScript connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1:
import * as mongoose from "mongoose";
import {Connection} from "mongoose";
import {options} from "../helpers/key";
mongoose.connect("mongodb://ds064188.mlab.com:64188/walter", options);
let db: Connection = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", () => {
console.log("we are connected");
});
export const conn: Connection = db;
开发者ID:vildantursic,项目名称:walter,代码行数:13,代码来源:connection.ts
示例2: require
// Imports
import * as mongoose from "mongoose";
import * as express from "express";
import * as Order from './api/orders/order.model'
import config = require('./config/config');
//Global Vars
const PORT = process.env.PORT || 3000;
const MONGO_URL = process.env.MONGO_URL || "mongodb://localhost/container-manager";
let app = express();
//Mongoose Connection
require('./api/orders/order.model');
require('./api/users/user.model');
mongoose.connect(MONGO_URL, function(err){
if(err) console.log(err)
else console.log(`connected to ${MONGO_URL}`)})
app.get(/\/client.{0,}\/.+\.jade/, (req, res, next) => {
res.render(config.root + req.path);
})
//Routes config
app.use(require('body-parser')());
// access bower_components via /scripts/...
app.use('/bower_components', express.static('bower_components'));
// access the client->app->home folder via /app/home
app.use('/client', express.static('client'));
// Routes
app.get('/', (req, res, next) => {
开发者ID:stevenfogel,项目名称:ELS,代码行数:31,代码来源:server.ts
示例3: require
kernel.bind<ParkingRepository>(TYPES.ParkingRepository).to(ParkingRepositoryBasic).inSingletonScope();
kernel.bind<UserRepository>(TYPES.UserRepository).to(UserRepositoryBasic).inSingletonScope();
kernel.bind<TrackingRepository>(TYPES.TrackingRepository).to(TrackingRepositoryBasic).inSingletonScope();
kernel.bind<GoogleDistanceMatrixKey>(TYPES.GoogleDistanceMatrixKey).to(GoogleDistanceMatrixKeyBasic).inSingletonScope();
// some variables
let version = '0.1.3';
let logger: Logger = kernel.get<Logger>(TYPES.Logger);
let parkingService: ParkingService = kernel.get<ParkingService>(TYPES.ParkingService);
let testDataService: TestDataService = kernel.get<TestDataService>(TYPES.TestDataService);
let userService: UserService = kernel.get<UserService>(TYPES.UserService);
let trackingService: TrackingService = kernel.get<TrackingService>(TYPES.TrackingService);
// mongodb (with mongoose) connection
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test');
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
var serverError = function (response: Response, message: string, user?: User) {
logger.error(message, user);
response.type('application/json; charset=utf-8');
response.writeHead(500);
response.write('{"error": "' + message + '"}');
response.end();
};
let app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
开发者ID:andi-git,项目名称:nodejs-test,代码行数:30,代码来源:app.ts
示例4: require
import express = require('express');
import path = require('path');
var port: number = 8080;
var app = express();
var compression = require('compression');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
import {TimeLog} from "./models/timelog.mongoose.model";
mongoose.connect('mongodb://localhost/angular-test');
app.use(compression());
app.use(bodyParser.urlencoded({'extended': 'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json());
app.use(express.static(path.resolve(__dirname, '../client/dist')));
var renderIndex = (req: express.Request, res: express.Response) => {
res.sendFile(path.resolve(__dirname, '../client/dist/app.html'));
};
app.get('/api/timelogs', function (req, res) {
TimeLog.find(function (err, timeLogs) {
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err) {
res.send(err);
}
res.json({data:timeLogs}); // return all timelogs in JSON format
});
});
开发者ID:alexeishirin,项目名称:angular-2-test,代码行数:31,代码来源:server.ts
示例5: require
/// <reference path="typings/express/express.d.ts" />
/// <reference path="typings/node/node.d.ts" />
import express = require('express');
import path = require('path');
import routes = require('./routes/routes');
var configDB = require('./config/database');
var mongoose = require('mongoose');
//TODO : Must be possible to type better
mongoose.connect(configDB.url); // connect to our database
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var passport = require('passport');
var session = require('express-session')
var flash = require('express-flash');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(favicon());
开发者ID:jabocop,项目名称:TSExpressBoilerplate,代码行数:30,代码来源:app.ts
示例6: require
/// <reference path='./app.d.ts' />
// enable source transformation
var asyncblock = require('asyncblock');
asyncblock.enableTransform();
// start our mongo connection
import config = require('./config');
var mongoose = require('mongoose');
mongoose.connect(config.props.mongo.uri);
// create our web server
import express = require('express');
export var app = express();
app.set('port', config.props.server.port);
app.use(express.bodyParser());
app.use(express.methodOverride());
// define our controllers
app.use(app.router);
require('./controllers')(app);
// register a global error handler
app.use((err, req, res, next) => {
switch (err.name) {
case 'ValidationError':
// mongoose validation errors
res.send(400, { error: err.toString() });
break;
default:
// unknown error type
开发者ID:jiashiwang,项目名称:typescript-node-mocha-example,代码行数:31,代码来源:server.ts
注:本文中的mongoose.connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论