nodejs-path

nodejs 关于路径处理的相关问题

路劲分类

  • 相对路径
    • ../xxx/a.jpg
    • ./xxx/a.jpg
    • xxx/a.jpg
  • 相对于网站的根目录
    • /xxx/a.jpg
  • 绝对路径(一般都不会用)
    • /Users/Navy/Desktop/code/demo/xxx/a.jpg

在web项目的前端发布构建过程中,经常需要处理css中的图片路径,清理图片缓存,上传图片到CDN等,所以一定会面临路径问题,而前端构建发布过程中经常借助nodejs。css中的图片使用最多的就是相对路径,以及相对于网站站点的根目录。

对于相对目录比较好处理,根据css当前路径和图片的相对路径,使用nodejs的path.resolve函数即可获取到图片的绝对路径。

相对于网站的根目录就稍微有点麻烦,因为当前css的路径是没啥作用,需要根据网站设置的静态文件目录处理,一般静态文件目录是public,static,assets等,那么根据静态文件目录和图片的路径及应用程序的根目录,通过nodejs的path.join函数也能比较好的处理这个路径问题。

nodejs 处理路径常用的函数

阅读全文 >

influx_query_language

InfluxQL is an SQL-like query language for interacting with data in InfluxDB. The following sections cover useful query syntax for exploring your data.

WHERE clause in InfluxQL:

  • The WHERE clause supports comparisons against strings, booleans, floats, integers, and against the time of the timestamp. It supports using regular expressions to match tags, but not to match fields.
  • Chain logic together using AND and OR, and separate using ( and ).
  • Acceptable comparators include:
1
2
3
4
5
6
7
= equal to
<> not equal to
!= not equal to
> greater than
< less than
=~ matches against
!~ doesn’t match against

阅读全文 >

write-sails-hook

how to write one sails-hook

  • you module package.json must have key ‘sails’ , it’s a object, with contain key isHook, if want to replace default hook, you can add key hookName, eg: sails:{isHook:true,hookName:’orm’}
  • export a function and return object, the first param is sails

sails hook how to load?

load hook principle : https://github.com/balderdashy/sails/blob/v0.12.3/lib/hooks/moduleloader/index.js#L507

replace default hook : https://github.com/balderdashy/sails/blob/v0.12.3/lib/hooks/moduleloader/index.js#L513

阅读全文 >

sails-orm-bug

when your sails version >= 0.12.2 ,and your config/connection.js adapter key is module ,such as :

1
2
3
4
5
6
7
8
devMongodb: {
module: 'sails-mongo',
host: process.env.MONGO_HOST || 'localhost',
port: process.env.MONGO_PORT || 57017,
user: process.env.MONGO_USER || '',
password: process.env.MONGO_PASS || '',
database: process.env.MONGO_DBNAME || 'koala'
}

it will appear this error “Cannot read property ‘config’ of undefined”. Beacause sails version >= 0.12.2 orm is Separated into independent modules “sails-hook-orm” , this module don’t support ‘module’ key as adapter.

you can solve it by two way:

  • change adapter key ‘module’ to ‘adapter’
  • rockback sails to lower version (<=0.12.1) , and delete module “sails-hook-orm”

阅读全文 >

粤ICP备18054847号-2
本站总访问量次 本站访客数人 本文总阅读量
{% if theme.baidu_push %} {% endif %}