express

Getting express.js to show a public folder

本秂侑毒 提交于 2020-01-23 09:57:30
问题 I've recently built a quick one page app using express.js, and this is really my first js framework (actually, my first js project, so I'm really new to this). I've got a subscription to the new typography.com cloud fonts, and I'm having trouble locating the "fonts" folder that I place in the public folder. Is there a way I need to add the folder and specify a route? Here's my app.js file: /** * Module dependencies. */ var express = require('express'), routes = require('./routes'), user =

Specifying password in MySQL connection string

谁说我不能喝 提交于 2020-01-23 08:08:06
问题 I created ExpressJS MVC app using MySQL as DB with Yeoman generator and in config.js I want to change MySQL connection strings, but I don't know to specify password in string. my string is mysql://root@localhost:3306/ Please help me. 回答1: Password and DB name also a part of connection string. Ex: mysql://root:password@localhost:port/dbName 回答2: Maybe you can try something like this: var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root',

nodeJS prevent timeout on res.download

纵然是瞬间 提交于 2020-01-23 08:07:26
问题 I have a POST call to my nodeJS server that searches for some data on the mongo database and returns a CSV file with the requested data. The problem is that the data search and processing exceeds the 2 minute nodeJS default timeout. On a diferent scenario y used: res.writeHeader(200,'application/json'); res.write('starting fetch .... '); to keep alive the request and prevent the timeout from the client by sending some res.write(''); from time to time. Now Im using res.download() to download

Node.JS downloading hundreds of files simultaneously

允我心安 提交于 2020-01-23 07:39:51
问题 I am trying to download more that 100 files at the same time. But when I execute the downloading function my macbook freezes(unable to execute new tasks) in windows also no download(but doesn't freeze) and no download progress in both case(idle network). Here is my download module: var express = require('express'); var router = express.Router(); var fs = require('fs'); var youtubedl = require('youtube-dl'); var links = require('../models/Links'); router.get('/', function (req, res, next) {

Why is the font different for res.end and res.send?

大憨熊 提交于 2020-01-23 06:36:41
问题 I have the following minimal basic express node js application: var express = require ('express'); var app = express (); app.get ('/', function (req, res) { res.send ('Hello'); }); app.listen (3000); When I access this site on localhost:3000 I get a response that looks like: If I change res.send ('Hello'); to res.end ('Hello'); , the response is a different font like: I am curious; why the difference? 回答1: If you pass a string to res.send() , it automatically assumes a Content-Type of html.

Why is the font different for res.end and res.send?

半腔热情 提交于 2020-01-23 06:36:09
问题 I have the following minimal basic express node js application: var express = require ('express'); var app = express (); app.get ('/', function (req, res) { res.send ('Hello'); }); app.listen (3000); When I access this site on localhost:3000 I get a response that looks like: If I change res.send ('Hello'); to res.end ('Hello'); , the response is a different font like: I am curious; why the difference? 回答1: If you pass a string to res.send() , it automatically assumes a Content-Type of html.

Error while trying to read file with node js from desktop

我的梦境 提交于 2020-01-23 03:22:31
问题 Im using the following code to read simple file from my desktop module.exports = function (app) { app.get('/aa', function(req, res) { fs = require('fs'); fs.readFile('‪C:\\Users\\t56789\\Desktop\\myfile.txt', 'utf8', function (err,data) { if (err) { return console.log(err); } console.log(data); res.send(data); }); }); when I hit in the browser /aa i got the following error { [Error: ENOENT, open 'C:\Users\t56789\WebstormProjects\Ro0.1\?C:\Users\t56789\Desktop\myfile.txt'] errno: -4058, code:

Catch-all root level routing in Express.js: considerations and reserving possible routes for future use?

倖福魔咒の 提交于 2020-01-23 02:41:08
问题 I'm using Express.js (3.0) to develop a Node web app; I'd like to have clean URLs for both user profiles: domain.com/username as well as for pages each user creates and shares: domain.com/username/pagename I really prefer the clean URLs to using something like domain.com/profile/username or domain.com/pages/username/pagename . The current route configuration for our development is bootstrapped like so: app.get('/', content.home); app.get('/about', content.about); app.get('/signup', users

Wait for socketio event inside express route

非 Y 不嫁゛ 提交于 2020-01-23 02:37:07
问题 I'm using express,socketio and socketio-client in my application. (I not very comfortable with nodejs stack...) to summarize my application flow : Client => node/express API + Socketoi server <=> nodejs (Socketio-client) browser send request to a nodejs/express (route /api) Do some request headers overwrites with middlewares In the route '/', server sends an emit to a nodejs (Socketio-client) after executing some logic, socketio-client emit an event with the logics result I need this result

Prevent zombie.js from loading only external resources

喜欢而已 提交于 2020-01-22 22:56:08
问题 I am using zombie.js to load a page from a local express server during a test. Unfortunately, there is a script element which calls out to Google Analytics. I would like to block this external script (gracefully) without preventing other (local) scripts from loading, if possible. I know that { runScripts : false } is available with calls to browser.visit() . However, that refuses to load any and all scripts on the page, not just those living on other hosts. Is this possible? 回答1: You should