node.js

TypeScript: Extend Express.Session interface with own class

北慕城南 提交于 2021-02-08 15:00:27
问题 I'm working on a Typescript project with npm packages. I want to add a property to the Express.Session interface. example Class: class User { name: string; email: string; password: string; } export = User; New d.ts file for the interface definition (don't want to edit express-session.d.ts): declare namespace Express { interface Session { user: User } } app.ts import User = require('./User'); function (req: express.Request, res: express.Response) { req.session.user //I want to use it like this

process.env.SOME_KEY is undefined

淺唱寂寞╮ 提交于 2021-02-08 14:59:59
问题 How do I set the value of process.env.SOME_KEY=some value in the operating system and then read it in my node application? I am running on Windows. I tried these steps: SET SOME_KEY=abc npm start But when I try to read process.env.SOME_KEY , I am getting "undefined". How do I set a env value and how do i read that in my code? 回答1: Try this: https://www.npmjs.com/package/dotenv All you need to do is add a .env with your environment variables, and require('dotenv').config() as soon as you can

2020年,大前端最为理想的技术体系

对着背影说爱祢 提交于 2021-02-08 14:35:46
大前端时代 现在的前端,已经不是只能制作 H5 网页,发送 Ajax 请求这样比较简单的岗位。一个真正意义上的大前端,可以同时开发跨平台桌面、移动端,小程序,中间件编写、 docker 自动化、云端服务器部署等。 写这篇文章的起因 最近很多朋友在吐槽,社区重复出现了很多篇 10分钟 精通**技术,万字长文彻底了解 ES 系列等文章,其实技术分享并没有什么问题,只是这样反复的技术文章出现说明, 目前的前端技术栈,已经基本稳固,再有出现,短期难有爆发。 关键是很多人询问,该怎么学习前端技术,工作经验很少等等。可是我的工作经验其实也很短呢。 刚好今晚与一起做即时通讯的后端同事在谈论技术,于是想写一篇关于 2020 年前端技术栈的文章。 以下是作者本人推荐掌握的技术栈: 首先是: 原生基础三剑客: JavaScript 、TypeScript 、 Node.js 抛出一个问题: 是不是有了React、Vue等框架就不需要Dom操作,不需要了解JQuery了? 答案:实现越复杂的功能, DOM 操作越重要,框架底层也是 DOM 操作。只不过加了些中间层( diff 算法等),想深入了解的可以 gitHub 看我的仓库 mini-react ,自己实现的 React 框架~ https: //github.com/JinJieTan/mini-react JavaScript 的学习:

uploading image to heroku using node and multer not work

百般思念 提交于 2021-02-08 14:16:16
问题 I am trying to upload image files to Heroku using Node backend and I can make it work, The same exact process work just fine on Localhost testing but after deploying my project to Heroku and testing it, there is an error in the process and the files wont upload BACKEND: let storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, './uploads') }, filename: function (req, file, cb) { cb(null, file.originalname) } }) const upload = multer({storage: storage}) router.post('/

uploading image to heroku using node and multer not work

风格不统一 提交于 2021-02-08 14:13:42
问题 I am trying to upload image files to Heroku using Node backend and I can make it work, The same exact process work just fine on Localhost testing but after deploying my project to Heroku and testing it, there is an error in the process and the files wont upload BACKEND: let storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, './uploads') }, filename: function (req, file, cb) { cb(null, file.originalname) } }) const upload = multer({storage: storage}) router.post('/

Mongoose populate across 2 databases

瘦欲@ 提交于 2021-02-08 13:58:10
问题 I have a node app that uses 2 databases. One is the the Names and the other for the rest of all the data. I have this connection setup: // DATABASE CONNECTION var APP_DB_URI = config.APP_DB; // mongodb://localhost:27017/app_db var app_DB = mongoose.createConnection(APP_DB_URI); var name_DB = app_DB.useDb(config.NAME_DB); // 'name_db' This connection is working properly. There's also no problem upon saving data to both app_db and names_db working perfect. But the problem is this: when I try to

ERROR: The process “node.exe” not found

99封情书 提交于 2021-02-08 13:55:15
问题 The Complete error is ERROR: The process "node.exe" not found. The filename, directory name, or volume label syntax is incorrect. [Finished in 0.3s with exit code 1] I am using Sublime text 2, and installed the NodeJS plugin, I tried to run a simple script, it runs fine with alt+r, but when I saved it (ctrl+s) it gave me that. Any idea on how to fix this? 回答1: Sounds like you don't have Node installed yet on your Windows machine? If you've already installed it, you can check your PATH

Create and Send Zip file -NODE JS

可紊 提交于 2021-02-08 13:44:22
问题 I'm trying to create and then send zip file to client. I know how to create it but I've got a problem with send it to client. I tried many ways. I'm sending POST request from Client and as response I want to send a file. This is my server-site example code var Zip = require('node-zip'); router.post('/generator', function(req, res, next) { var zip = new Zip; zip.file('hello.txt', 'Hello, World!'); var options = {base64: false, compression:'DEFLATE'}; fs.writeFile('test1.zip', zip.generate

Express middleware, next and Promises

对着背影说爱祢 提交于 2021-02-08 13:41:30
问题 There is very simple Express router with handler: router.get('/users/:userId/roles/:roleId', function(req, res, next){ const roleId = req.params.roleId; res.rest.resource = UserModel.findOne({ _id: req.params.userId}).exec().then(function(usr) { console.log(req.params.roleId); // => undefined console.log(roleId); // => okay here const result = usr.roles.find( role => String(role._id) === String(roleId)); return result; }); next(); }); As it seen accessing req.params.roleId within promise

npm install in GitHub Action fails with “ENOENT: no such file or directory” - Works fine elsewhere

我是研究僧i 提交于 2021-02-08 13:29:14
问题 I am currently working on replacing our Drone CI installation with GitHub Actions. The Action Workflow I have so far boils down to the following .github/workflows/ci.yml file: on: [ push, pull_request ] name: CI jobs: test: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Install Node uses: actions/setup-node@v1 with: node-version: '13.x' - name: Install Dependencies run: npm install The log itself comes out as a long series of npm WARN tar ENOENT: no such file