Sing's Log

Knowledge worth sharing


  • Home

  • Tags

  • Timeline

  • Portfolio

  • Search

Install nodejs program as windows service by nssm

Posted on 2018-05-29 | Edited on 2023-11-21 |

Steps to install windows service

  1. Create a start.bat file with content npm start
  2. Download nssm
  3. Extract it and go to nssm/win64 folder
  4. Type nssm install service-name from command prompt
  5. Select start.bat as Application Path, you could also add your startup Arguments here
  6. Start service with nssm start service-name
  7. You could find it already registered as windows service :)

NSSM commands reference

You could type nssm anytime to see this document

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
M:\nssm-2.24\win64>nssm
NSSM: The non-sucking service manager
Version 2.24 64-bit, 2014-08-31
Usage: nssm <option> [<args> ...]

To show service installation GUI:

nssm install [<servicename>]

To install a service without confirmation:

nssm install <servicename> <app> [<args> ...]

To show service editing GUI:

nssm edit <servicename>

To retrieve or edit service parameters directly:

nssm get <servicename> <parameter> [<subparameter>]

nssm set <servicename> <parameter> [<subparameter>] <value>

nssm reset <servicename> <parameter> [<subparameter>]

To show service removal GUI:

nssm remove [<servicename>]

To remove a service without confirmation:

nssm remove <servicename> confirm

To manage a service:

nssm start <servicename>

nssm stop <servicename>

nssm restart <servicename>

nssm status <servicename>

nssm rotate <servicename>

Reference

http://nssm.cc

Install Redis master-slave-sentinel on linux

Posted on 2018-05-18 | Edited on 2023-11-21 |

Before start

  1. Download and install redis from official site
  2. redis excutable commands are under bin folder, configs are under etc folder, logs are under var folder
    Read more »

Resolve concurrency limit with Bluebird-Promise.map

Posted on 2018-05-10 | Edited on 2023-11-21 |

ECONNRESET when making thousands requests

In situation doing thousands of http requests, it is easy to get error ECONNRESET, for example :

1
2
3
4
5
6
7
8
require('isomorphic-fetch');

const promises = []
for(var i=0; i<10000; i++){
promises.push(fetch('http://example.com/'+i));
}

const results = await Promise.all(promises)
Read more »

Find ports status on Windows

Posted on 2018-05-03 | Edited on 2023-11-21 |

To find ports status on windows, there is a default Windows GUI - Resource Monitor or you could use netstat via command prompt.

Read more »

Transact-SQL cheat sheet

Posted on 2018-04-25 | Edited on 2023-11-21 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- Get current datetime
GETDATE()

-- Get year of datetime
YEAR(GETDATE())

-- Get difference between dates
DATEDIFF(dateformat, startdate, enddate)

-- Subtract date, e.g.: DATEADD(HOUR, -11, GETDATE())
DATEADD(Unit of time, value, date)

-- Avalable Unit of time value
NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, WEEKDAY, WEEK, DAY, DAYOFYEAR, MONTH, QUARTER, YEAR

-- Between
select * from User where CreatedDate between '2016-09-26' and '2016-09-27'

-- Order by
select * from User order by column desc

-- Group by
select UserCode, Count(*) from User group by UserCode

-- Select top 10
SELECT TOP (10) * from User

Linux Remote Desktop Viewer to Windows error connecting to host

Posted on 2018-04-14 | Edited on 2023-11-21 |

Today When I connect to Windows through Remote Desktop Viewer got error connecting to host prompt.
After searching the solution is to remove the server I’m having issue in $home/.freerdp/known_hosts and reconnecting again.

1
2
[sing@study ~]$ vi ~/.freerdp/known_hosts
# In Vim, remove the line start with server ip you are connecting to by `dd`, and `:wq` to save the file.

Reference: https://superuser.com/questions/834447/vinagre-remote-desktop-viewer-for-gnome-isnt-working-out-of-box

HttpClient PostAsync/GetAsync JSON Example

Posted on 2018-04-11 | Edited on 2023-11-21 |

PostAsync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
static readonly HttpClient Client = new HttpClient();
public async Task<T> PostAsync<T>(string url, object data) where T : class, new()
{
try
{
string content = JsonConvert.SerializeObject(data);
var buffer = Encoding.UTF8.GetBytes(content);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await Client.PostAsync(url, byteContent).ConfigureAwait(false);
string result = await response.Content.ReadAsStringAsync();
if (response.StatusCode != HttpStatusCode.OK)
{
logger.Error($"GetAsync End, url:{url}, HttpStatusCode:{response.StatusCode}, result:{result}");
return new T();
}
logger.Info($"GetAsync End, url:{url}, result:{result}");
return JsonConvert.DeserializeObject<T>(result);
}
catch (WebException ex)
{
if (ex.Response != null)
{
string responseContent = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
throw new System.Exception($"response :{responseContent}", ex);
}
throw;
}
}

GetAsync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
static readonly HttpClient Client = new HttpClient();
public async Task<string> GetAsync(string url, object data)
{
try
{
string requestUrl = $"{url}?{GetQueryString(data)}";
logger.Info($"GetAsync Start, requestUrl:{requestUrl}");
var response = await Client.GetAsync(requestUrl).ConfigureAwait(false);
string result = await response.Content.ReadAsStringAsync();
logger.Info($"GetAsync End, requestUrl:{requestUrl}, HttpStatusCode:{response.StatusCode}, result:{result}");
return result;
}
catch (WebException ex)
{
if (ex.Response != null)
{
string responseContent = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
throw new Exception($"Response :{responseContent}", ex);
}
throw;
}
}

private static string GetQueryString(object obj)
{
var properties = from p in obj.GetType().GetProperties()
where p.GetValue(obj, null) != null
select p.Name + "=" + HttpUtility.UrlEncode(p.GetValue(obj, null).ToString());

return String.Join("&", properties.ToArray());
}

Abbreviation in Software Engineering

Posted on 2018-04-10 | Edited on 2023-11-21 |

This sheet is to record abbreviation in my daily work as a software engineer.

Abbreviation Full name Explain
CDC Change data capture Use to sync one db data change to another db
MPLS Multi-Protocol Label Switching Link site to site network like both in same network
IDC Internet Data Center Buildings where we put servers
REST REpresentational State Transfer Architectural style defines a set of constraints on HTTP
CNAME Canonical Name A DNS record to point a/b/c domain to d domain so you don’t have to add A record in a/b/c
ACL Access Control List An ACL specifies which users or system processes are granted access to objects

Jenkins migration

Posted on 2018-04-10 | Edited on 2023-11-21 |
  1. Copy existing jenkins folder, exclude workspace
  2. Modify jenkins port in Jenkins.xml, default 8080
  3. Modify AD Domain and rename an account to yours in config.xml
  4. Create / Start Jenkins service in cmd with administrator mode:

    1
    2
    sc create <jenkins-service-name> <path/to/jenkins.exe>
    sc start <jenkins-service-name>
  5. View migrated jenkins in your browser with port specify above, default http://localhost:8080

How Redux work ?

Posted on 2018-04-02 | Edited on 2023-11-21 |

If you want to understand how Redux work, createStore(reducer) is the core function you should know and try to implement yourself. Here is a basic example of Redux, don’t worry I will break it down later :

Read more »

1…345…9
Sing Ming Chen

Sing Ming Chen

Sing's log, a developer's blog

83 posts
232 tags
GitHub E-Mail Linkedin Facebook StackOverflow
© 2023 Sing Ming Chen
Powered by Hexo v3.9.0
|
Theme — NexT.Gemini v6.3.0