Tag: javascript

关于Node.js的问题 SChema和模型

关于Node.js的问题 架构,模型和npm。 我是node.js的新手,并按照步骤在mongoose文档中创build模式和模型。 http://mongoosejs.com/docs/ 我正在尝试使用kittens.js输出我在index.js中创build的模型,但我不确定是否正确。 有错误当我尝试编译时, C:\Atom\initial\index.js:11 db.on('error', console.error.bind(console, 'connection_error')); ^ TypeError: Cannot read property 'on' of undefined at Object.<anonymous> (C:\Atom\initial\index.js:11:3) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3 我在index.js中有以下代码。 var express = require('express'); var mongoose = […]

我的邮政路线有问题吗?

所以我使用一个简单的CRUD风格的网页sequelize。 我的问题是我能够将input的数据input到mysql工作台,它存储在表中,但在网页本身没有任何反应。 //uses var=Posts which contains the fields userName //and userPosts in my database var db = require("../models"); // route to create posts app.post("/api/posts", function(req, res) { console.log(req.body); db.Posts.create({ userName: req.body.username, userPosts: req.body.user_post, }) .then(function(dbPost) { res.redirect('/dashboard'); res.json(dbPost); }); }); 提前感谢任何帮助!

Node.js的帮助,如何发送客户端请求到一个电子邮件?

我一直在努力Node.js,我想要做的一件事是如何发送客户端请求到实际的电子邮件,而不是我的服务器。 例如,我被一个企业聘用,客户端点击“提交”,电子邮件被发送到该企业的电子邮件或他们正在尝试联系。 任何人都知道响应方法是什么? 我似乎无法在网上find任何教程,而Nodemailer教程都是关于从服务器发送电子邮件,这不是我想要做的。

如何在React Native和VSCode中使用带(或不带)Typescript的Nodestream

我使用ReactNativify (而不是更多的hacky的rn-nodeify方法)将一些基于Node的软件包移植到React Native,以在依赖关系树中浏览/ 清除 Node API对象。 我正在开发VSCode。 使用ReactNativify,您可以在.babelrc中使用babel-plugin-rewrite-require (或者在rn-cli.config.js + transformer.js使用javascript): { … "plugins": [ ["rewrite-require", { "aliases": { "constants": "constants-browserify", "crypto": "react-native-crypto", "dns": "node-libs-browser/mock/dns", "domain": "domain-browser", "stream": "stream-browserify", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", "_stream_readable": "readable-stream/readable", "_stream_transform": "readable-stream/transform", "_stream_writable": "readable-stream/writable", … etcetera } }] … } ( 在这里看一个完整的例子) 这工作得很好,我在VSCode中得到了很好的代码完成/智能感知等。 现在我想在如下的MyStream.js使用Node的Stream: import { Duplex } from 'stream' […]

nodejs npm同时启动错误

我在package.json中有以下代码: "scripts": { "start": "concurrently –kill-others \"npm run _server:run\" \"ng serve –aot –progress=false –proxy-config proxy.conf.json\"", "lint:client": "ng lint", "lint:server": "tslint './server/**/*.ts' -c ./server/tslint.json –fix", "test:client": "ng test", "e2e:client": "ng e2e", "build": "ng build –prod –sm=false –aot –output-path=dist/client && npm run _server:build", "_server:run": "tsc -p ./server && concurrently \"tsc -w -p ./server\" \"nodemon –debug dist/server/bin/www.js\" ", […]

windows nt错误和节点js代码中的elifecycle错误

我正在尝试解决一些我的朋友写的代码的问题。 他不能回答我的问题,所以我问你,如果我按下程序中的特定button,服务器将崩溃。 这是我得到的npmdebugging日志: `0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Programme\\nodejs\\\\node.exe', 1 verbose cli 'C:\\Programme\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 1 verbose cli 'start' ] 2 info using npm@2.11.3 3 info using node@v0.12.7 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info prestart KTB@0.0.0 6 info start KTB@0.0.0 7 verbose unsafe-perm in lifecycle […]

node-mandrill通过服务器发送邮件

这是一个关于正确使用node-mandrill的新手问题,最有可能在节点本身,因为我仍然试图学习它。 但是由于我看到很多例子直接从客户端使用mandrill的api键,因此揭示它,我想知道它是如何工作时,但在这一点卡住: 我有一个app.js服务公共文件夹… app.js var express = require('express'); var mandrill = require('node-mandrill')(API_KEY); var app = express(); app.use(express.static('public')); app.listen(PORT); function sendEmail ( _name, _email, _subject, _message) { mandrill('/messages/send', { message: { to: 'EMAIL', from: [{email: _email , name: _name}], subject: _subject, text: _message } }, function(error, response){ if (error) console.log( error ); else console.log(response); }); } […]

mongoose – 铸造ObjectId失败

我正在一个小型的博客应用程序,我在这里被困在这个错误 – { "message": "Cast to ObjectId failed for value \" 597c4ce202ca9c353fc80e8a\" at path \"_id\" for model \"Blog\"", "name": "CastError", "stringValue": "\" 597c4ce202ca9c353fc80e8a\"", "kind": "ObjectId", "value": " 597c4ce202ca9c353fc80e8a", "path": "_id" } 我正在使用findById – 这是代码 app.get("/blogs/:id", function(req, res) { Blog.findById(req.params.id, function(err, foundBlog) { if (err) { res.send(err); } else { res.render("show", { blog: foundBlog }); } […]

错误:加载块0失败。 – webpack试图加载0.js

我有以下项目结构: |-mainFile.js |-scripts – |-Library1.js |-Library2.js 库文件使用requirejs define([], function() {})语法。 所以我把它放到了webpack.config.js中: module.exports = { resolve: { modules: [ path.resolve(__dirname, 'scripts'), // The normal path "node_modules" ] }, /** … **/ } 然后我在webpack的入口点mainFile.js中做这个: require(["Library1", "Library2"], function(Library1, Library2) { … }); 我得到这个错误: GET http://localhost:3000/0.js [HTTP/1.1 404 Not Found 3ms] Error: Loading chunk 0 failed. Stack trace: onScriptComplete@http://localhost:3000/player/webpack_build.js:100:24 […]

刮cheerio.js,得到:错误:只能在暂停时执行操作

试图从这个网站刮取威士忌的名字,image_url和描述: https ://www.thewhiskyexchange.com/c/33/american-whiskey ? filter = true#productlist-filter using cheerio.js。 我想把这些信息转换成一个JSON对象数组来存储在我的MongoDB中。 无法显示整个网站的html,但这里是无序列表的相关基本结构的一部分: <body> <div class="siteWrapper"> <div class="wrapper"> <div class="products-wrapper"> <ul class="products-list"> <li> <a> <div class="product-content"> <div class="information"> <p class="name"> " Jack Daniel's Old No. 7" <span>Small Bottle</span> </p> </div> </div> </a> </li> <li></li> <li></li> etc. </all closing tags> 刚开始试图在<p class="name">得到威士忌的名字,没有任何来自<span>标签的文本,我在浏览器控制台中使用了这个jQuery代码,它正是我所需要的: $('ul.products-list > li').each(function(index) { const nameOnly […]