Michał Michalczuk
Ciklum / Stibo Systems
infoShare Academy
Michał Michalczuk
const express = require('express');
const app = express();
const port = 3000;
app.get('/api/greeter', (req, res) => res.send({
message: `Hello ${req.query.name}!`
}));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
{
"name": "expressjs-example",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.3"
}
}
const express = require('express');
const app = express();
const port = 3000;
app.get('/api/greeter', (req, res) => res.send({
message: `Hello ${req.query.name}!`
}));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
{
"name": "expressjs-example",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.3"
}
}
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium
PhantomJS is a headless web browser scriptable with JavaScript.
PhantomJS development is suspended until further notice
nuget package: Microsoft.AspNetCore.NodeServices
module.exports = function(callback) {
// In this trivial example, we don't need to receive any
// parameters - we just send back a string
var message = 'Hello from Node at ' + new Date().toString();
callback(/* error */ null, message);
};
NodeScripts/my-script.js
public async Task<string> About(
[FromServices] INodeServices nodeServices)
{
return await nodeServices.InvokeAsync<string>(
"NodeScripts/my-script.js"
);
}
Controllers/MyController.cs
NodeServices has a pluggable hosting/transport mechanism, because it is an abstraction over various possible ways to invoke Node.js from .NET.
...all the built-in hosting mechanisms work by launching Node as a separate process on the same machine as your .NET code.
using EdgeJs;
public static async void Start()
{
var func = Edge.Func(@"
return function (data, cb) {
cb(null, 'Node.js ' +
process.version +
' welcomes ' +
data);
}
");
Console.WriteLine(await func(".NET"));
}
var edge = require('edge');
var helloWorld = edge.func(`
async (input) => {
return ".NET Welcomes " + input.ToString();
}
`);
helloWorld('JavaScript', function (error, result) {
if (error) throw error;
console.log(result);
});
https://github.com/aspnet/JavaScriptServices/tree/master/src/Microsoft.AspNetCore.NodeServices
https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node
https://gldraphael.com/blog/generating-pdfs-from-an-asp-net-core-app-using-a-node-library/
*thing which speakers need