express

Issue with express static middleware and subdirectory

♀尐吖头ヾ 提交于 2020-01-05 04:22:20
问题 I have this folder as my website structure -views -index -post -public -css -js -images -app.js But a post link can be: mywebsite.com/posts/a-link-example So, when I use express static middleware like this: app.use(express.static(__dirname + '/public')); it only works in pages without a "subdirectory" like example.com/home example.com/contact but not on example.com/posts/post-name I can use of course: app.use('/posts, express.static(__dirname + '/public')); but is there a better way to do it?

How to delete an nested object based on its ObjectId?

喜你入骨 提交于 2020-01-05 04:19:25
问题 I have this nested Schema for my courses collections, there is a sessions array in every course and a students array in every session and every student is an object consisting of a property of userName with a value of ObjectId refering to my users collections and another property names status containing some number. I want to delete an student object from my students array of my session with its _id. I know it is possible to unwind arrray to get to a single object but I need a neat way like

Nodejs Mongodb update multiple collections

余生长醉 提交于 2020-01-05 04:15:16
问题 In mongodb have two collections for now Event and Packages. So basically the model looks like this Event Model const mongoose = require('mongoose'); mongoose.Promise = global.Promise; const Schema = mongoose.Schema; const bcrypt = require('bcrypt-nodejs'); const EventSchema = new Schema({ _id: mongoose.Schema.Types.ObjectId, eventname: { type: String, required : true, }, eventdesc: { type: String, required : true, }, createdAt: { type: Date, default: Date.now }, updatedAt: { type: Date,

Can't add object to MongoDB array inside a document

风格不统一 提交于 2020-01-05 04:11:12
问题 I'm building an API for my chat application and I wrote the endpoint below to save new messages in MongoDB. The messages themselves are an array. Testing this endpoint with Postman returns the newly created message in the response but the message is not added to my array of messages. router.post('/:id/messages', async (request, response) => { const chatMessage = new Message({ type: request.body.type, body: request.body.body, author: request.body.author }); try { const newMessage = await

New line in express.js message

强颜欢笑 提交于 2020-01-05 04:09:46
问题 Is it possible to make a new line in the message notification? "\n" or "\r\n" just disappear but there's no new line set. I also tried var endOfLine = require('os').EOL; instead of \n. Doesn't work sadly. res.render('settings.ejs', { user: req.user, isAuthenticated: true, message: 'Changed User(s):' + changearray + '\n(Notice: You can\'t affect Users with higher Settingrights.)' }); Probabbly a stupid/easy question but I don't get it working... Thanks in advance. 回答1: You can use html tags.

browserify 'Error: Cannot find module' in trying to fix 'Uncaught reference error: require is not defined'

末鹿安然 提交于 2020-01-05 04:05:31
问题 I am having a very similar, or almost exact, issue to @RachelD from this thread (Node.js + Angular = Uncaught ReferenceError: require is not defined) regarding the Uncaught reference error. However, when I run my 'browserify' command as stated in the directions here (https://github.com/substack/node-browserify) and exactly as shown below (I included my directory as well for reference)... myname@compname:~/workspace/MyApp $ browserify /app/scripts/controllers/main.js > bundle.js I am getting a

MongoDB mongoose subdocuments created twice

允我心安 提交于 2020-01-05 03:57:07
问题 I am using a simple form that can be used to register an article to a website. the back-end looks like this: // Post new article app.post("/articles", function(req, res){ var newArticle = {}; newArticle.title = req.body.title; newArticle.description = req.body.description; var date = req.body.date; var split = date.split("/"); newArticle.date = split[1]+'/'+split[0]+'/'+split[2]; newArticle.link = req.body.link; newArticle.body = req.body.body; var platforms = req.body.platforms; console.log

expressjs - not able to load my stylus stylesheet to jade html page

你离开我真会死。 提交于 2020-01-05 03:05:25
问题 In my express app, i am trying to load the style properties from styles module engine. But i couldn't able to load my style at all. here is my folder structure: myNodeApp -node_modules -styles -style.css -style.styl -views -index.jade and here is my app.js code where i call use the stylus. var http = require("http"), express = require("express"), stylus = require("stylus"), app = express(); app.set('view engine', 'jade'); app.set('views', './views'); app.use(stylus.middleware({ debug : true,

I want to use Stormpath, Express.js, and Node.js. Do I want stormpath-express or express-stormpath?

一世执手 提交于 2020-01-05 02:50:08
问题 I posted an earlier question ("What do I need to know to transfer a working Node project?") after I had a Node project working on a server, and couldn't get it to work at all on my laptop. In the course of drafting another comment, I noticed something funny. The person who probably gave me the most help asked my version numbers for Node and Stormpath, and when I gave them, he said that my version number from my package.json didn't look like a stormpath-express version number. What I found out

ERR_SSL_PROTOCOL_ERROR with Heroku, Node, Express, SSL

北城余情 提交于 2020-01-04 22:25:30
问题 I recently enabled SSL for my Heroku-hosted website, wildcodemonkey.com, but when I visit it in Chrome I see the error "ERR_SSL_PROTOCOL_ERROR". My research indicated that the SSL connection terminates at Heroku's router, which then passes the request along via HTTP to my express/node site. Consequently, I did not set up 'https' in my server and have been expecting standard HTTP connections. My SSL configuration is such that my CSR, key and cert were passed along to Heroku. I'm using the SSL