express

when I require “express” I need to know if its an object or function

廉价感情. 提交于 2020-01-21 12:07:29
问题 Given my code const express = require("express") const app = express() console.log(typeof app) console.log(typeof express) My terminal tells me that both of these variables are functions! This makes no sense to me because I can access properties from each of them as if they were objects and yet when I do a typeof in console.log my terminal tells me they are both functions. Can someone please explain to me what these variables are and why its possible to access their properties as if they were

Pass a variable from javascript to ejs

被刻印的时光 ゝ 提交于 2020-01-21 11:08:53
问题 I want to use a variable which is declared in javascript file to a ejs file. javascript: var express = require('express'); var app = express(); var myVar = 1; In the ejs file , where I want to use that variable inside a few if statements ,I have to declare it again in order to be able to use it. ejs file: var myVar = 1; if ( my Var ) .... How can I avoid this?Or is there a way for creating a configuration file which is accesible from both javascript and ejs? I tried also to use: app.locals

Error: Package exports for <path to project folder>/node_modules/@babel/helper-compilation-targets' do not define a '.' subpath

眉间皱痕 提交于 2020-01-21 07:58:26
问题 I just created a new project folder and ran the following commands: npm init npm install express npm install express-react-views react react-dom Created index.js with express imported and views for a sample jsx file. When I run on localhost, I get this error: Error: Package exports for '<path_to_project_folder>/node_modules/@babel/helper-compilation-targets' do not define a '.' subpath at applyExports (internal/modules/cjs/loader.js:485:15) at resolveExports (internal/modules/cjs/loader.js

Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead

此生再无相见时 提交于 2020-01-21 06:53:12
问题 I just freshly installed Node.js and now I'm trying to run a simple script, but I get the following error message: Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead. at Function.<anonymous> (module.js:383:11) at Object.<anonymous> (/home/shawn/.node_libraries/express@2.5.9/index.js:4:21) at Module._compile (module.js:446:26) at Object..js (module.js:464:10) at Module.load (module.js:353:31) at Function._load (module.js:311:12) at Module

NodeJS Express not serving '/socket.io/socket.io.js'

穿精又带淫゛_ 提交于 2020-01-21 06:35:50
问题 I am trying to build NodeJS/Express/SocketIO application. Imports: var express = require('express') , app = express() , server = require('http').createServer(app) , io = require('socket.io').listen(server)... Configuration: app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app

502 proxy error in Express.js while integrating with Apache [closed]

老子叫甜甜 提交于 2020-01-21 04:11:25
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am hosting apache and node.js server together with apache server proxying to node server.My framework is express.js and I am using amCharts.I have timeout for proxying set to 600.When I open my website I get only the static content and not the dynamic content of amCharts. This is my server side code: var

Socket.io emit from Express controllers

纵然是瞬间 提交于 2020-01-21 03:27:26
问题 I'm quite new to Node.js / Express, and I'm using it as a backend for an AngularJS app. I've looked all over StackOverflow for some help on my problem, but I can't seem to figure out how to port the suggestions to my code. My application works as follows: A long running Scala process periodically sends my Node.js application log messages. It does this by posting to an HTTP API When the post is received, my application writes the log message to MongoDB The log messages are then sent in real

What is the most efficient way of sending files between NodeJS servers?

旧街凉风 提交于 2020-01-21 02:18:07
问题 Introduction Say that on the same local network we have two Node JS servers set up with Express: Server A for API and Server F for form. Server A is an API server where it takes the request and saves it to MongoDB database (files are stored as Buffer and their details as other fields) Server F serves up a form, handles the form post and sends the form's data to Server A. What is the most efficient way to send files between two NodeJS servers where the receiving server is Express API? Where

How to render images with react on server side?

我与影子孤独终老i 提交于 2020-01-20 19:43:07
问题 How can I render images and css files on server side with React? Here is my server code: const express = require('express') const router = express.Router() const ReactDOM = require('react-dom/server'); import Master from '../../../client/Master' router.get('/', (req, res) => { res.render('test.html', {reactOutput: ReactDOM.renderToString(<Master/>)}); }); Master component: import React from "react"; import Intro from "./pages/Intro"; import Footer from "./components/Footer"; import Header

How is the express req.session object persisted?

☆樱花仙子☆ 提交于 2020-01-20 16:50:08
问题 I'm very new to learning Node and Express, and I'm still trying to wrap my head around the code flow with express. Suppose we have code that looks like this in a session.js: app.post('/session', notLoggedIn, function(req, res) { User.findOne({ username: req.body.username, password: req.body.password }, function (err, user) { if (err) { return next(err); } if (user) { req.session.user = user; res.redirect('/users'); } else { res.redirect('/session/new'); } }); }); Assuming the User is a