Skip to content

Commit c526d3a

Browse files
committed
first release
0 parents  commit c526d3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+9873
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
main.cpp
2+
main
3+
/www
4+
.env

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 NODEPP
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Node++
2+
3+
**Node++** is an innovative open source project that aims to make it easier to create applications in **C++**. This project introduces a high-level abstraction layer that allows developers to write **C++** code in a way that is similar to how they would write code in **NodeJS**. With **Node++**, developers can leverage the advantages of the **C++** language while benefiting from the ease of use and flexibility that **NodeJS** offers. This unique combination of features makes **Node++** a powerful tool for creating high-performance and scalable applications. Additionally, since it is an open source project, anyone can contribute and improve **Node++** to fit their specific needs.
4+
5+
- **uNode++:** compatible with embed devices [here](https://github.com/EDBCREPO/uNODEPP)
6+
- **Node++:** compatible with PC and esp32 [here](https://github.com/EDBCREPO/NODEPP)
7+
8+
## Dependencies
9+
- Openssl `sudo apt install libssl-dev`
10+
- Zlib `sudo apt install zlib1g-dev`
11+
12+
## Key Features
13+
14+
- Allows writing C++ code as if writing in NodeJS
15+
- Adds a high-level abstraction layer to simplify C++ application development
16+
- Includes an event loop that can handle multiple events and tasks on a single thread of execution
17+
- Supports coroutines, which allows running multiple tasks concurrently on a single thread
18+
- Includes support for TCP, TLS, UDP, HTTP, and HTTPS, making it easy to create networked applications
19+
- Includes a regular expression engine for processing and manipulating text strings
20+
- Compatible with several platforms, including Windows, macOS, Linux, ESP32, and ESP8266
21+
- Open source project, meaning anyone can contribute and improve it
22+
- Has extensive documentation and an active community of developers willing to help
23+
24+
## Installation
25+
26+
```bash
27+
g++ -o main main.cpp -I ./include ; ./main
28+
```
29+
30+
## Usage
31+
32+
To use **Node++**, simply include the `node++.h` header file in your project and start writing **C++** code as if you were writing in **NodeJS**. Here's a simple example:
33+
34+
```cpp
35+
#include <node++/node++.h>
36+
37+
using namespace nodepp;
38+
39+
void _Ready() {
40+
console::log("Hello World!");
41+
}
42+
```
43+
44+
Examples - [here](https://github.com/EDBCREPO/NODEPP/tree/main/examples)
45+
46+
## Contribution
47+
48+
If you want to contribute to **Node++**, you are welcome to do so! You can contribute in several ways:
49+
50+
- Improving the documentation
51+
- Reporting bugs and issues
52+
- Adding new features or improving existing ones
53+
- Writing tests and ensuring compatibility with different platforms
54+
- Before submitting a pull request, make sure to read the contribution guidelines.
55+
56+
## License
57+
58+
**Node++** is distributed under the MIT License. See the LICENSE file for more details.

examples/AdvanceObserver.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <node++/node++.h>
2+
#include <node++/observer.h>
3+
4+
using namespace nodepp;
5+
6+
observer_t obj ({
7+
{ "string", "hola mundo" },
8+
{ "int", 10 }
9+
});
10+
11+
void _Ready() {
12+
13+
obj.on( "string", []( any_t A, any_t B ){
14+
console::log( (string_t) A, "|", (string_t) B );
15+
});
16+
17+
obj.on( "int", []( any_t A, any_t B ){
18+
console::log( (int) A, "|", (int) B );
19+
});
20+
21+
obj.set([]( observer_t state ){ return observer_t ({
22+
{ "string", (string_t) state["string"] + " de mierda" },
23+
{ "int", (int) state["int"] + 50 }
24+
}); });
25+
26+
}

examples/AdvancedHTTPSServer.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <node++/node++.h>
2+
#include <node++/https.h>
3+
#include <node++/timer.h>
4+
#include <node++/path.h>
5+
#include <node++/date.h>
6+
#include <node++/fs.h>
7+
8+
using namespace nodepp;
9+
10+
ssl_t ssl( "./ssl/key.pem", "./ssl/cert.pem" );
11+
12+
void server( int process ){
13+
14+
auto server = https::server([=]( https_t cli ){
15+
16+
string_t dir = "www/index.html";
17+
if( cli.path.size() > 1 )
18+
dir = path::join( "www", cli.path );
19+
20+
console::log( cli.path, process );
21+
22+
if( !fs::exists_file(dir) ){
23+
cli.write_headers( 404, {{ { "content-type", "text/plain" } }} );
24+
cli.write( regex::format("404: Oops time: ${0}",date::fulltime()) );
25+
cli.close(); return;
26+
}
27+
28+
auto str = fs::readable( dir );
29+
30+
if( cli.headers["Range"].empty() ){
31+
32+
cli.write_headers( 200, {{
33+
{ "Content-Length", string::to_string(str.size()) },
34+
// { "Cache-Control", "public, max-age=3600" },
35+
{ "Content-Type", path::mimetype(dir) }
36+
}});
37+
38+
if(!regex::test(path::mimetype(dir),"audio|video","i") )
39+
stream::pipe( str, cli );
40+
41+
} else if( !cli.headers["Range"].empty() ) {
42+
43+
array_t<string_t> range = regex::match_all(cli.headers["Range"],"\\d+","i");
44+
ulong rang[2]; rang[0] = string::to_ulong( range[0] );
45+
rang[1] = min( rang[0]+CHUNK_MB(10), str.size()-1 );
46+
47+
cli.write_headers( 206, {{
48+
{ "Content-Range", regex::format("bytes ${0}-${1}/${2}",rang[0],rang[1],str.size()) },
49+
{ "Content-Type", path::mimetype(dir) },
50+
{ "Accept-Range", "bytes" }
51+
}});
52+
53+
str.set_range( rang[0], rang[1] );
54+
stream::pipe( str, cli );
55+
56+
}
57+
58+
}, &ssl );
59+
60+
server.listen( "localhost", 8000, [=]( ssocket_t server ){
61+
console::log("server started at https://localhost:8000");
62+
});
63+
64+
}
65+
66+
void _Ready() { server( os::pid() ); }

examples/AdvancedHTTPServer.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <node++/node++.h>
2+
#include <node++/timer.h>
3+
#include <node++/http.h>
4+
#include <node++/path.h>
5+
#include <node++/date.h>
6+
#include <node++/fs.h>
7+
8+
using namespace nodepp;
9+
10+
void server( int process ){
11+
12+
auto server = http::server([=]( http_t cli ){
13+
14+
string_t dir = "www/index.html";
15+
if( cli.path.size() > 1 )
16+
dir = path::join( "www", cli.path );
17+
18+
console::log( cli.path, process );
19+
20+
if( !fs::exists_file(dir) ){
21+
cli.write_headers( 404, {{ { "content-type", "text/plain" } }} );
22+
cli.write( regex::format("404: Oops time: ${0}",date::fulltime()) );
23+
cli.close(); return;
24+
}
25+
26+
auto str = fs::readable( dir );
27+
28+
if( cli.headers["Range"].empty() ){
29+
30+
cli.write_headers( 200, {{
31+
{ "Content-Length", string::to_string(str.size()) },
32+
// { "Cache-Control", "public, max-age=3600" },
33+
{ "Content-Type", path::mimetype(dir) }
34+
}});
35+
36+
if(!regex::test(path::mimetype(dir),"audio|video","i") )
37+
stream::pipe( str, cli );
38+
39+
} else if( !cli.headers["Range"].empty() ) {
40+
41+
array_t<string_t> range = regex::match_all(cli.headers["Range"],"\\d+","i");
42+
ulong rang[2]; rang[0] = string::to_ulong( range[0] );
43+
rang[1] = min( rang[0]+CHUNK_MB(10), str.size()-1 );
44+
45+
cli.write_headers( 206, {{
46+
{ "Content-Range", regex::format("bytes ${0}-${1}/${2}",rang[0],rang[1],str.size()) },
47+
{ "Content-Type", path::mimetype(dir) },
48+
{ "Accept-Range", "bytes" }
49+
}});
50+
51+
str.set_range( rang[0], rang[1] );
52+
stream::pipe( str, cli );
53+
54+
}
55+
56+
});
57+
58+
server.listen( "localhost", 8000, [=]( socket_t server ){
59+
console::log("server started at http://localhost:8000");
60+
});
61+
62+
}
63+
64+
void _Ready() { server( os::pid() ); }

examples/AdvancedPromises.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <node++/node++.h>
2+
#include <node++/promise.h>
3+
#include <node++/timer.h>
4+
5+
using namespace nodepp;
6+
7+
void _Ready() {
8+
9+
auto t = timer::add([](){
10+
static int i=0; i++;
11+
console::log("new interval",i);
12+
return ( i >= 20 ) ? -1 : 1 ;
13+
}, 1000 );
14+
15+
promise::resolve<int>([=]( function_t<void,int> res ){
16+
timer::timeout([=](){ res(10); },1000);
17+
},[=]( int res ){
18+
console::log("first promise resolved:",res);
19+
});
20+
21+
promise::resolve<int>([=]( function_t<void,int> res ){
22+
timer::timeout([=](){ res(20); },5000);
23+
},[]( int res ){
24+
console::log("second promise resolved:",res);
25+
});
26+
27+
promise::resolve<int>([=]( function_t<void,int> res ){
28+
timer::timeout([=](){ res(30); },10000);
29+
},[]( int res ){
30+
console::log("third promise resolved:",res);
31+
});
32+
33+
}

examples/AdvancedStreams.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <node++/node++.h>
2+
#include <node++/path.h>
3+
#include <node++/fs.h>
4+
5+
using namespace nodepp;
6+
7+
void _Ready() {
8+
auto _rdb = fs::readable( path::join( process::cwd(), "www", "kloud.mp4" ) );
9+
auto _wrt = fs::writable( path::join( process::cwd(), "www", "mojon.mp4" ) );
10+
11+
_rdb.onData.on([]( string_t chunk ){
12+
console::log( chunk.size() );
13+
});
14+
15+
_rdb.onClose.on([](){
16+
console::log( "done" );
17+
});
18+
19+
stream::pipe( _rdb, _wrt );
20+
}

examples/BufferFree.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <node++/node++.h>
2+
#include <node++/timer.h>
3+
4+
using namespace nodepp;
5+
6+
void _Ready() {
7+
8+
ptr_t<int> var = new int(10);
9+
10+
if( !var.null() ) console::log( *var, &var );
11+
else console::log( "undefined" );
12+
13+
console::log("free"); var.free();
14+
15+
if( !var.null() ) console::log( *var, &var );
16+
else console::log( "undefined" );
17+
18+
}

examples/Coroutine.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <node++/node++.h>
2+
3+
using namespace nodepp;
4+
5+
void _Ready() {
6+
7+
process::loop::add([=](){ static int itr = 10;
8+
_Start
9+
while( itr --> 0 ){
10+
console::done(" Coroutine 1:",itr); _Yield(1);
11+
}
12+
_Stop
13+
});
14+
15+
process::loop::add([=](){ static int itr = 10;
16+
_Start
17+
while( itr --> 0 ){
18+
console::error("Coroutine 2:",itr); _Yield(1);
19+
}
20+
_Stop
21+
});
22+
23+
}

0 commit comments

Comments
 (0)