Skip to content

iapicca/dart_node_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dart_node_example

"how to" import a dart function in node.js

js/ts example

  • set up node dependencies
npm init -y && \
npm install express && \
npm install --save-dev typescript @types/node @types/express ts-node-dev
  • create the file tsconfig.json with the code below
{
    "compilerOptions": {
      "allowJs": true,
      "target": "ES6",
      "module": "commonjs",
      "strict": true,
      "esModuleInterop": true,
      "skipLibCheck": true,
      "outDir": "./dist",
      "rootDir": "./src"
    },
    "include": ["src"]
  }  
  • create the file `src/greeting.js with the following code
export function greeting() {
    return "Hello from JS"
}
  • create the file src/index.ts with the code below
import express, { Request, Response } from 'express';
import { greeting } from './greeting.js';

const app = express();
const port = 3000;

app.get('/', (req: Request, res: Response) => {
  res.send(greeting());
});

app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
});

notes

see issue

About

"how to" import a dart function in node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published