How to run require(“express”); from a TypeScript A

2019-08-26 10:40发布

问题:

I'm new to "Angular", "typescript" and "Electron". I created a "server.js" file with the basic example of express. What is the correct way to create a local server for the local network?

I want to create an "Angular" "Electron" App with a button to run the express server, but I don't know what to code in order to execute the "server.js" file.

function runLocalServer() {

  servidor = require('server.js');  // This line is a error!

  ....

Thanks for your help.

回答1:

TypeScript accepts a normal require() as well as the import syntax. For example:

const express = require('express');
// OR
import * as express from 'express';